| Package | flash.geom |
| Class | public class Bezier |
| Implements | IParametric |
Class Bezier represents a Bezier second-order curve in parametric view,
and is given by start, control and end points on the plane.
It exists to support the curveTo() method. Methods and properties of this class
give access to the geometric properties of the curve.
Pt on the Bezier second-order curve is computed using formula:Pt = S*(1-t)2
+ 2*C*(1-t)*t + E*t2
(1)t(time) — time-iterator of the pointS(start) — initial control (anchor) point (t=0)С(control) — direction pointE(end) — final control (anchor) point (t=1)Interactive demo
You can use "Left" and "Right" keys to control the iterator.
Curve control points are dragable.
S and E always
lie on the Bezier curve and limit itt = 0.5 -
lies in the middle of the segment, that connects С and the
middle of the SE segmentC generally does not belongs to the curve
and lies on the intersection of the tangents to the curve from points
S and EС belongs to SE then the curve is singularSE equals 2/3 of the ∆SCE triangle squaret changing in infinite limits is a parabola.
If Bezier curve lies on parabola then this parabola is considered to be the parent for it.Line interprets segment this way to simplify
it's usage together with Bezier class.See also
| Property | Defined by | ||
|---|---|---|---|
| area : Number [read-only]
Calculates and returns the area of the figure limited by Bezier curve and
line
SE. | Bezier | ||
| bounds : Rectangle [read-only]
Calculates and returns a bounds rectangular of a segment of Bezier curve.
Property isSegment=false does not change result of calculations. | Bezier | ||
| control : Point
Direction point of Bezier curve.
| Bezier | ||
| end : Point
End anchor point of Bezier curve.
| Bezier | ||
| externalCentroid : Point [read-only]
Gravity center of the figure limited by Bezier curve and lines
SC and CE. | Bezier | ||
| internalCentroid : Point [read-only]
Gravity center of the figure limited by Bezier curve and line
SE. | Bezier | ||
| isSegment : Boolean
Defines is the Bezier curve is infinite in both directions or is limited within
the bounds of value of iterators from 0 up to 1.
The Bezier curve is constructed with using iterator within the bounds from 0 up to 1, however, it can be constructed in any bounds. The Bezier curve constructed from a minus of infinity up to plus of infinity is a parabola. Current value isSegment influence on the results of methods: intersectionBezier intersectionLine getClosest Line.intersectionBezier | Bezier | ||
| length : Number [read-only]
Calculates length of the Bezier curve
| Bezier | ||
| parabolaFocusPoint : Point [read-only]
| Bezier | ||
| parabolaVertex : Number [read-only]
Calculates and returns time-iterator of top of the parabola.
| Bezier | ||
| start : Point
Initial anchor point of Bezier curve.
| Bezier | ||
| triangleArea : Number [read-only]
Calculates and returns the area of a triangle ∆SCE, which is formed of
control points
start, control, end. | Bezier | ||
| triangleCentroid : Point [read-only]
Gravity center of triangle
SCE. | Bezier | ||
| Property | Defined by | ||
|---|---|---|---|
| controlPoint : Point | Bezier | ||
| endPoint : Point | Bezier | ||
| __isSegment : Boolean = true | Bezier | ||
| startPoint : Point | Bezier | ||
| Method | Defined by | ||
|---|---|---|---|
|
Bezier(start:Point, control:Point, end:Point, isSegment:Boolean = true)
Create new Bezier object.
| Bezier | ||
|
angleOffset(value:Number, fulcrum:Point = null):void
Rotate a curve concerning to a point
fulcrum on the value angle
If point fulcrum is not set, used (0,0)
| Bezier | ||
|
Creates and returns a copy of current object Bezier.
| Bezier | ||
|
getClosest(fromPoint:Point):Number
Вычисляет и возвращает time-итератор точки на кривой,
ближайшей к точке | Bezier | ||
|
getPoint(time:Number, point:Point = null):Point
Realization of formula 1
Calculates and returns object Point which representing a point on a Bezier curve, specified by the parameter time. | Bezier | ||
|
getSegment(fromTime:Number = 0, toTime:Number = 1):Bezier
Вычисляет и возвращает сегмент кривой Безье.
| Bezier | ||
|
getSegmentLength(time:Number):Number
Calculates length of a segment of Bezier curve from a starting point
up to a point on a curve which passed in parameter time.
| Bezier | ||
|
getTangentAngle(time:Number = 0):Number
Tangent is line that touches but does not intersect with bezier.
| Bezier | ||
|
getTimeByDistance(distance:Number):Number
Вычисляет time-итератор точки, находящейся на заданной дистанции
по кривой от точки
startДля вычисления равноуделенных последовательностей точек, например для рисования пунктиром, используйте метод getTimesSequence | Bezier | ||
|
getTimesSequence(step:Number, startShift:Number = 0):Array
Вычисляет и возвращает массив time-итераторов точек,
находящихся друг от друга на дистанции по кривой,
заданной параметром
step.Если задан параметр startShift, то расчет производится
не от точки start, а от точки на кривой, находящейся на
заданнй этим параметром дистанции.Значение startShift конвертируется в остаток от деления на step. | Bezier | ||
|
Результат вычисления пересечения кривой Безье с другой кривой Безье может дать следующие результаты:
- если пересечение отсутствует, возвращается null; - если пересечение произошло в точках (от одной до четырех точек), будет возвращен объект Intersection, и time-итераторы точек пересечения на данной кривой Безье будут находиться в массиве currentTimes. | Bezier | ||
|
Результат вычисления пересечения кривой Безье с линией может дать следующие результаты:
- если пересечение отсутствует, возвращается null; - если пересечение произошло в одной или двух точках, будет возвращен объект Intersection, и time-итераторы точек пересечения на кривой Безье будут находиться в массиве currentTimes. | Bezier | ||
|
offset(dX:Number = 0, dY:Number = 0):void
Moves a curve on the prescribed distance on axes X and Y.
| Bezier | ||
|
setPoint(time:Number, x:Number, y:Number):void
Изменяет кривую таким образом, что заданная параметром time точка кривой
Pt,
будет находиться в заданных параметрами x и y координатах.Если один из параметров x или y не задан,
то точка Pt не изменит значение соответствующей координаты. | Bezier | ||
|
toString():String
| Bezier | ||
| Method | Defined by | ||
|---|---|---|---|
|
initInstance(start:Point, control:Point, end:Point, isSegment:Boolean = true):void
| Bezier | ||
| Constant | Defined by | ||
|---|---|---|---|
| PRECISION : Number = 1e-10 [static]
| Bezier | ||
| area | property |
area:Number [read-only]
Calculates and returns the area of the figure limited by Bezier curve and
line SE.
The area of this figure makes 2/3 areas of a triangle ∆SCE, which is formed of
control points start, control, end.
Accordingly, the rest of a triangle makes 1/3 its areas.
public function get area():Number
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const randomBezier:Bezier = randomBezier();
trace("bezier area: "+randomBezier.area);
| bounds | property |
bounds:Rectangle [read-only]
Calculates and returns a bounds rectangular of a segment of Bezier curve.
Property isSegment=false does not change result of calculations.
public function get bounds():Rectangle
| control | property |
control:Point [read-write]Direction point of Bezier curve.
Implementation public function get control():Point
public function set control(value:Point):void
| controlPoint | property |
protected var controlPoint:Point
| end | property |
end:Point [read-write]
End anchor point of Bezier curve. Iterator time is equal to one
public function get end():Point
public function set end(value:Point):void
| endPoint | property |
protected var endPoint:Point
| externalCentroid | property |
externalCentroid:Point [read-only]
Gravity center of the figure limited by Bezier curve and lines SC and CE.
public function get externalCentroid():Point
| internalCentroid | property |
internalCentroid:Point [read-only]
Gravity center of the figure limited by Bezier curve and line SE.
public function get internalCentroid():Point
| __isSegment | property |
protected var __isSegment:Boolean = true
| isSegment | property |
isSegment:Boolean [read-write]
Defines is the Bezier curve is infinite in both directions or is limited within
the bounds of value of iterators from 0 up to 1.
The Bezier curve is constructed with using iterator within the bounds from 0 up to 1,
however, it can be constructed in any bounds.
The Bezier curve constructed from a minus of infinity up to plus of infinity is a parabola.
Current value isSegment influence on the results of methods:
intersectionBezier
intersectionLine
getClosest
Line.intersectionBezier
The default value is true.
public function get isSegment():Boolean
public function set isSegment(value:Boolean):void
See also
| length | property |
length:Number [read-only]Calculates length of the Bezier curve
Implementation public function get length():Number
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
trace("bezier length: "+bezier.length);
| parabolaFocusPoint | property |
parabolaFocusPoint:Point [read-only]Implementation
public function get parabolaFocusPoint():Point
See also
| parabolaVertex | property |
parabolaVertex:Number [read-only]Calculates and returns time-iterator of top of the parabola.
Implementation public function get parabolaVertex():Number
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const randomBezier:Bezier = randomBezier();
trace("parabola vertex time: "+randomBezier.parabolaVertex);
| start | property |
start:Point [read-write]
Initial anchor point of Bezier curve. Iterator time is equal to zero.
public function get start():Point
public function set start(value:Point):void
| startPoint | property |
protected var startPoint:Point
| triangleArea | property |
triangleArea:Number [read-only]
Calculates and returns the area of a triangle ∆SCE, which is formed of
control points start, control, end.
public function get triangleArea():Number
See also
| triangleCentroid | property |
triangleCentroid:Point [read-only]
Gravity center of triangle SCE.
public function get triangleCentroid():Point
| Bezier | () | constructor |
public function Bezier(start:Point, control:Point, end:Point, isSegment:Boolean = true)Create new Bezier object. If parameters are not passed, all control points are created in coordinates 0,0
Parametersstart:Point — initial point of Bezier curve
|
|
control:Point — control point of Bezier curve
|
|
end:Point — end point of Bezier curve
|
|
isSegment:Boolean (default = true) — operating mode
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
trace("random bezier: "+bezier);
| angleOffset | () | method |
public function angleOffset(value:Number, fulcrum:Point = null):void
Rotate a curve concerning to a point fulcrum on the value angle
If point fulcrum is not set, used (0,0)
value:Number — rotation angle
|
|
fulcrum:Point (default = null) — center of rotation.
|
| clone | () | method |
public function clone():BezierCreates and returns a copy of current object Bezier.
ReturnsBezier —
Bezier.
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
const clone:Bezier = bezier.clone();
trace("bezier: "+bezier);
trace("clone: "+clone);
trace(bezier == clone);
| getClosest | () | method |
public function getClosest(fromPoint:Point):Number
Вычисляет и возвращает time-итератор точки на кривой,
ближайшей к точке fromPoint.
В зависимости от значения свойства isSegment
возвращает либо значение в пределах от 0 до 1, либо от минус
бесконечности до плюс бесконечности.
fromPoint:Point — произвольная точка на плоскости.
|
Number — Number time-итератор точки на кривой.
|
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
TODO: [Dembicki] example
| getPoint | () | method |
public function getPoint(time:Number, point:Point = null):Point
Realization of formula 1
Calculates and returns object Point which representing a point on a Bezier curve,
specified by the parameter time.
time:Number — iterator of the point on curve
|
|
point:Point (default = null) |
Point — Point point on the Bezier curve;If passed the parameter time equal to 1 or 0, object Point equivalent to start
or end will be returned, but not objects exact start or end.
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
const time:Number = Math.random();
const point:Point = bezier.getPoint(time);
trace(point);
| getSegment | () | method |
public function getSegment(fromTime:Number = 0, toTime:Number = 1):BezierВычисляет и возвращает сегмент кривой Безье.
ParametersfromTime:Number (default = 0) — time-итератор начальной точки сегмента
|
|
toTime:Number (default = 1) — time-итератор конечной точки сегмента кривой
|
Bezier —
Bezier;
|
segment1
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
const segment1:Bezier = bezier.getSegment(1/3, 2/3);
const segment2:Bezier = bezier.getSegment(-1, 2);
| getSegmentLength | () | method |
public function getSegmentLength(time:Number):NumberCalculates length of a segment of Bezier curve from a starting point up to a point on a curve which passed in parameter time.
Parameterstime:Number — parameter time of the end point of a segment.
|
Number — Number length of arc.
|
See also
| getTangentAngle | () | method |
public function getTangentAngle(time:Number = 0):NumberTangent is line that touches but does not intersect with bezier. Computes and returns the angle of tangent line in radians. The return value is between positive pi and negative pi.
Parameterstime:Number (default = 0) — time of bezier point
|
Number — Number angle in radians;
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
| getTimeByDistance | () | method |
public function getTimeByDistance(distance:Number):Number
Вычисляет time-итератор точки, находящейся на заданной дистанции
по кривой от точки start
Для вычисления равноуделенных последовательностей точек,
например для рисования пунктиром, используйте метод getTimesSequence
distance:Number — дистанция по кривой до искомой точки.
|
Number — Number time iterator of bezier point;
|
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
trace(bezier.getTimeByDistance(-10); // negative value
trace(bezier.getTimeByDistance(bezier.length/2); // value between 0 and 1
| getTimesSequence | () | method |
public function getTimesSequence(step:Number, startShift:Number = 0):Array
Вычисляет и возвращает массив time-итераторов точек,
находящихся друг от друга на дистанции по кривой,
заданной параметром step.
Если задан параметр startShift, то расчет производится
не от точки start, а от точки на кривой, находящейся на
заданнй этим параметром дистанции.
Значение startShift конвертируется в остаток от деления на step.
step:Number — шаг, дистанция по кривой между точками.
|
|
startShift:Number (default = 0) — дистанция по кривой, задающая смещение первой
точки последовательности относительно точки start
|
Array — Array sequence of points on bezier curve;
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
// TODO: [Dembicki] example
| initInstance | () | method |
protected function initInstance(start:Point, control:Point, end:Point, isSegment:Boolean = true):voidParameters
start:Point |
|
control:Point |
|
end:Point |
|
isSegment:Boolean (default = true) |
| intersectionBezier | () | method |
public function intersectionBezier(target:Bezier):Intersection
Результат вычисления пересечения кривой Безье с другой кривой Безье может дать следующие результаты:
- если пересечение отсутствует, возвращается null;
- если пересечение произошло в точках (от одной до четырех точек), будет возвращен объект Intersection,
и time-итераторы точек пересечения на данной кривой Безье будут находиться в массиве currentTimes.
time-итераторы точек пересечения target будут находиться в массиве targetTimes;
- также может произойти совпадение кривых. В этом случае результатом будет являться кривая - объект Bezier (isSegment=true),
которая будет доступна как свойство coincidenceBezier в возвращаемом объекте Intersection;
На результаты вычисления пересечений оказывает влияние свойство isSegment как текущего объекта,
так и значение isSegment объекта target.
target:Bezier |
Intersection —
Intersection
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
| intersectionLine | () | method |
public function intersectionLine(target:Line):Intersection
Результат вычисления пересечения кривой Безье с линией может дать следующие результаты:
- если пересечение отсутствует, возвращается null;
- если пересечение произошло в одной или двух точках, будет возвращен объект Intersection,
и time-итераторы точек пересечения на кривой Безье будут находиться в массиве currentTimes.
time-итераторы точек пересечения target будут находиться в массиве targetTimes;
- если кривая Безье вырождена, то может произойти совпадение.
В этом случае результатом будет являться отрезок - объект Line (isSegment=true),
который будет доступен как свойство coincidenceLine в возвращаемом объекте Intersection;
На результаты вычисления пересечений оказывает влияние свойство isSegment как текущего объекта,
так и значение isSegment объекта target.
target:Line |
Intersection —
Intersection
|
See also
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
| offset | () | method |
public function offset(dX:Number = 0, dY:Number = 0):voidMoves a curve on the prescribed distance on axes X and Y.
ParametersdX:Number (default = 0) — offset by X
|
|
dY:Number (default = 0) — offset by Y
|
| setPoint | () | method |
public function setPoint(time:Number, x:Number, y:Number):void
Изменяет кривую таким образом, что заданная параметром time точка кривой Pt,
будет находиться в заданных параметрами x и y координатах.
Если один из параметров x или y не задан,
то точка Pt не изменит значение соответствующей координаты.
time:Number — time-итератор точки кривой.
|
|
x:Number — новое значение позиции точки по оси X.
|
|
y:Number — новое значение позиции точки по оси Y.
|
import flash.geom.Bezier;
import flash.geom.Point;
function randomPoint():Point {
return new Point(Math.random()*stage.stageWidth, Math.random()*stage.stageHeight);
}
function randomBezier():Bezier {
return new Bezier(randomPoint(), randomPoint(), randomPoint());
}
const bezier:Bezier = randomBezier();
trace(bezier);
bezier.setPoint(0, 0, 0);
bezier.setPoint(0.5, 100, 100);
bezier.setPoint(1, 200, 0);
trace(bezier); // (start:(x=0, y=0), control:(x=100, y=200), end:(x=200, y=0))
| toString | () | method |
public function toString():StringReturns
String — String
|
| PRECISION | constant |
protected static const PRECISION:Number = 1e-10