Quadratic¶
Overview¶
Quadratic Bezier segment
Good reference: http://cagd.cs.byu.edu/~557/text/ch2.pdf
@author Jonathan Olson <jonathan.olson@colorado.edu>
Class Quadratic¶
Constructor¶
new Quadratic( start : Vector2, control : Vector2, end : Vector2 )¶
Instance Methods¶
setStart( start : Vector2 ) : this¶
Sets the start point of the Quadratic.
getStart() : Vector2¶
Returns the start of this Quadratic.
setControl( control : Vector2 ) : this¶
Sets the control point of the Quadratic.
getControl() : Vector2¶
Returns the control point of this Quadratic.
setEnd( end : Vector2 ) : this¶
Sets the end point of the Quadratic.
getEnd() : Vector2¶
Returns the end of this Quadratic.
positionAt( t : number ) : Vector2¶
Returns the position parametrically, with 0 <= t <= 1.
NOTE: positionAt( 0 ) will return the start of the segment, and positionAt( 1 ) will return the end of the segment.
This method is part of the Segment API. See Segment.js's constructor for more API documentation.
tangentAt( t : number ) : Vector2¶
Returns the non-normalized tangent (dx/dt, dy/dt) of this segment at the parametric value of t, with 0 <= t <= 1.
NOTE: tangentAt( 0 ) will return the tangent at the start of the segment, and tangentAt( 1 ) will return the tangent at the end of the segment.
This method is part of the Segment API. See Segment.js's constructor for more API documentation.
curvatureAt( t : number ) : number¶
Returns the signed curvature of the segment at the parametric value t, where 0 <= t <= 1.
The curvature will be positive for visual clockwise / mathematical counterclockwise curves, negative for opposite curvature, and 0 for no curvature.
NOTE: curvatureAt( 0 ) will return the curvature at the start of the segment, and curvatureAt( 1 ) will return the curvature at the end of the segment.
This method is part of the Segment API. See Segment.js's constructor for more API documentation.
subdivided( t : number ) : Quadratic[]¶
Returns an array with up to 2 sub-segments, split at the parametric t value. Together (in order) they should make up the same shape as the current segment.
This method is part of the Segment API. See Segment.js's constructor for more API documentation.
invalidate()¶
Clears cached information, should be called when any of the 'constructor arguments' are mutated.
getStartTangent() : Vector2¶
Returns the tangent vector (normalized) to the segment at the start, pointing in the direction of motion (from start to end)
getEndTangent() : Vector2¶
Returns the tangent vector (normalized) to the segment at the end, pointing in the direction of motion (from start to end)
getTCriticalX() : number¶
getTCriticalY() : number¶
getNondegenerateSegments() : Segment[]¶
Returns a list of non-degenerate segments that are equivalent to this segment. Generally gets rid (or simplifies) invalid or repeated segments.
getBounds() : Bounds2¶
Returns the bounds of this segment.
offsetTo( r : number, reverse : boolean ) : Quadratic[]¶
Returns an array of quadratic that are offset to this quadratic by a distance r
@param r - distance @param reverse
degreeElevated() : Cubic¶
Elevation of this quadratic Bezier curve to a cubic Bezier curve
approximateOffset( r : number ) : Quadratic¶
@param r - distance
getSVGPathFragment() : string¶
Returns a string containing the SVG path. assumes that the start point is already provided, so anything that calls this needs to put the M calls first
strokeLeft( lineWidth : number ) : Quadratic[]¶
Returns an array of lines that will draw an offset curve on the logical left side
strokeRight( lineWidth : number ) : Quadratic[]¶
Returns an array of lines that will draw an offset curve on the logical right side
getInteriorExtremaTs() : number[]¶
intersection( ray : Ray2 ) : RayIntersection[]¶
Hit-tests this segment with the ray. An array of all intersections of the ray with this segment will be returned. For details, see the documentation in Segment.js
windingIntersection( ray : Ray2 ) : number¶
Returns the winding number for intersection with a ray
writeToContext( context : CanvasRenderingContext2D )¶
Draws the segment to the 2D Canvas context, assuming the context's current location is already at the start point
transformed( matrix : Matrix3 ) : Quadratic¶
Returns a new quadratic that represents this quadratic after transformation by the matrix
getSignedAreaFragment() : number¶
Returns the contribution to the signed area computed using Green's Theorem, with P=-y/2 and Q=x/2.
NOTE: This is this segment's contribution to the line integral (-y/2 dx + x/2 dy).
reparameterized( a : number, b : number ) : Quadratic¶
Given the current curve parameterized by t, will return a curve parameterized by x where t = a * x + b
reversed() : Quadratic¶
Returns a reversed copy of this segment (mapping the parametrization from [0,1] => [1,0]).
serialize() : SerializedQuadratic¶
Returns an object form that can be turned back into a segment with the corresponding deserialize method.
getOverlaps( segment : Segment, epsilon ) : Overlap[] | null¶
Determine whether two lines overlap over a continuous section, and if so finds the a,b pair such that p( t ) === q( a * t + b ).
@param segment @param [epsilon] - Will return overlaps only if no two corresponding points differ by this amount or more in one component. @returns - The solution, if there is one (and only one)
Instance Properties¶
degree : number¶
Degree of the polynomial (quadratic)
Static Methods¶
deserialize( obj : SerializedQuadratic ) : Quadratic¶
Returns a Quadratic from the serialized representation.
extremaT( start : number, control : number, end : number ) : number¶
One-dimensional solution to extrema
getOverlaps( quadratic1 : Quadratic, quadratic2 : Quadratic, epsilon ) : Overlap[]¶
Determine whether two Quadratics overlap over a continuous section, and if so finds the a,b pair such that p( t ) === q( a * t + b ).
NOTE: for this particular function, we assume we're not degenerate. Things may work if we can be degree-reduced to a quadratic, but generally that shouldn't be done.
@param quadratic1 @param quadratic2 @param [epsilon] - Will return overlaps only if no two corresponding points differ by this amount or more in one component. @returns - The solution, if there is one (and only one)
Type SerializedQuadratic¶
- type: "Quadratic"
- startX: number
- startY: number
- controlX: number
- controlY: number
- endX: number
- endY: number
Source Code¶
See the source for Quadratic.ts in the kite repository.