- AbstractEdge
- CircularEdge

addPath
angleToBody
bodyToEdge
chordError
depthOfArc
distanceToEdge
distanceToLine
distanceToPoint
edgeToBody
edgeToWorld
findVertexContact
forgetPosition
getBody
getBottomBody
getCenterBody
getCentroidBody
getCentroidRadius
getCentroidWorld
getClassName
getCurvature
getDecoratedVertexes
getIndex
getLeftBody
getNormalBody
getPointOnEdge
getRadius
getRightBody
getTopBody
getVertex1
getVertex2
highlight
improveAccuracyEdge
intersection
intersectionPossible
isStraight
isWithinArc
isWithinArc2
isWithinReflectedArc
isWithinReflectedArc2
maxDistanceTo
nearestPointByAngle
outsideIsOut
pointOffset
setCentroidRadius
setVertex2
testCollisionEdge
findAngleLowHigh
findDepth
isWithinArc
make

- new
Circular (body, vertex1, vertex2, center_body, clockwise, outsideIsOut, opt_spacing?): CircularEdgeEdge The Edge starts at

`vertex1`

(given in body coordinates) proceeding along a circular arc with given center to the ending`vertex2`

. The direction of the arc is given by the`clockwise`

parameter. When the`outsideIsOut`

variable is`true`

, the outside of the circle is considered the outside of the RigidBody. Both Vertexes must be equidistant from the center, otherwise an exception is thrown.#### Parameters

##### body: RigidBody

Edge will be added to this RigidBody

##### vertex1: Vertex

Edge starts at this Vertex, given in body coordinates

##### vertex2: Vertex

Edge finishes at this Vertex, given in body coordinates

##### center_body: Vector

center of the circular arc, in body coordinates

##### clockwise: boolean

direction of the arc

##### outsideIsOut: boolean

`true`

means the region outside of the circle is considered the outside of the RigidBody, so the edge is convex.`False`

indicates a concave edge.`Optional`

opt_spacing: numberthe distance between 'decorated' mid-point Vertexes.

#### Returns CircularEdge

#### Throws

if the Vertexes are not equidistant from the center within

`CircularEdge.TINY_POSITIVE`

tolerance#### Throws

if

`vertex1`

is already connected to a 'next' Edge#### Throws

if

`vertex2`

is already connected to a 'previous' Edge

`Private`

angle_angle_high_ : number

Any point on the arc falls between angle_low and angle_high, where angle_low < angle_high. Note that angle_low might be startAngle or finishAngle (modulo 2 pi), same with angle_high. In math convention, angle_high is between angle_low and 3 pi.

`Private`

angle_angle_low_ : number

Any point on the arc falls between angle_low and angle_high, where angle_low < angle_high. Note that angle_low might be startAngle or finishAngle (modulo 2 pi), same with angle_high. In math convention, angle_low is between -pi and pi.

`Protected`

body_the RigidBody that this edge is a part of

`Private`

center_position of the center, in body coords

`Protected`

centroidcentroidRadius_ : number = NaN

the maximum distance from centroid to any point on this edge

`Protected`

centroid_the 'center' of this edge, an arbitrary point selected to minimize the centroid radius of this edge

`Private`

clockwise_clockwise_: boolean

when true, arc goes clockwise from startAngle to finishAngle.

`Private`

completecompleteCircle_ : boolean

true when this is a complete circle

`Private`

decorateddecoratedAngle_ : number

the angle between decorated Vertexes

`Private`

depth_depth_: number

depth is used to limit how far a penetration is regarded as a collision. 'depth of arc' is thickest distance between arc and line connecting arc ends.

`Private`

finishfinishAngle_ : number

finish angle, in mathematical body coords (in radians, 0 = 3 o'clock, increase counter-clockwise) startAngle and finishAngle are same in body or edge coords

`Protected`

index_index_: number = -1

index of this edge in the body's list of edges

`Private`

outsideoutsideIsOut_ : boolean

when true, the outside of the circle is outside of the object.

`Private`

radius_radius_: number

radius of the edge; NOTE: radius is positive, but getCurvature() returns negative for concave edge

`Private`

startstartAngle_ : number

starting angle, in mathematical body coords (in radians, 0 = 3 o'clock, increase counter-clockwise) startAngle and finishAngle are same in body or edge coords

`Protected`

v1_the previous vertex, in body coords; matches the next (second) vertex of the previous edge

`Protected`

v2_the next vertex, in body coords

- chord
Error (): number Returns the maximum distance between this Edge and any chord between Vertexes on this Edge (including decorated mid-point Vertexes). A chord is the straight line between two adjacent Vertexes.

Here is a picture of a curved Edge, the chord between two Vertexes, V1, V2, and the

*chord error*is the maximum distance between the chord and curved Edge.Note that having more decorated mid-point Vertexes results in a smaller chord error, because the chords are closer to the curve.

See Vertex for more about decorated mid-point Vertexes

#### Returns number

the maximum distance between this Edge and a chord between any Vertexes on this Edge

- distance
To (edge): numberEdge Returns smallest distance between this Edge and the given Edge. Returns

`NaN`

in cases where the calculation can't be done. One of the Edges must be curved.**TO DO**distanceToEdge is not used currently... delete it? or use it in places like`CircleStraight.testCollision`

and`CircleCircle.testCollision`

?#### Parameters

##### edge: Edge

the Edge to measure distance to

#### Returns number

smallest distance between this Edge and the given Edge, or

`NaN`

when the calculation cannot be done#### Throws

if both Edges are StraightEdges.

- distance
To (p_body): numberLine Returns distance from the given point (in body coordinates) to the extended line of this Edge, where the extensions continue beyond the endpoints of this Edge. For a CircularEdge the extended line is taken to be the full circle. Positive distance means the point is outside of this Edge, negative means inside.

#### Parameters

##### p_body: Vector

the point to find distance from, in body coords

#### Returns number

distance from the given point to the extended line of this Edge

- distance
To (p_body): numberPoint Returns signed distance of the given point (in body coordinates) to this Edge along a line that is normal to this Edge, or infinity if beyond an endpoint of this Edge. Distance is positive if it is on the side of the line that the normal points towards, otherwise negative.

#### Parameters

##### p_body: Vector

the point to find distance from, in body coords

#### Returns number

signed distance from the given point to this Edge (positive if point is on side the normal points towards) or infinity if beyond the endpoint of this Edge

- find
Vertex (v, p_body, distTol): null | RigidBodyCollisionContact Returns a RigidBodyCollision representing the contact point if the given Vertex is close to this Edge. Closeness is specified by the given distance tolerance. Note that this

**does not consider velocity tests**for a contact. If the point does not lie along any normal to this Edge, then it is not close; this occurs when the point is past the endpoints of this Edge.If the point is near, then the returned RigidBodyCollision will have the following information set:

`body`

is set to the RigidBody of the Vertex`normalBody`

is set to the RigidBody of this Edge- impact point is set to the nearest point on this Edge, in world coords
- distance is set to the distance of Vertex from this Edge; negative distance means penetration into this Edge.
- normal is set to the unit normal vector at the nearest point on this Edge, in world coords
`r2`

is based on current position of this Edge's RigidBody

Additionally, if this Edge is curved, the following are also set:

`ballNormal, radius2, u2`

.#### Parameters

#### Returns null | RigidBodyCollision

a RigidBodyCollision representing the contact point, or

`null`

if not close enough.

- get
Center (_p_body?): VectorBody Returns center of curvature of this Edge. For an oval shape, this calculates the curvature at the given point on the Edge. For a circle or straight line, the curvature is the same at any point on the Edge.

#### Parameters

`Optional`

_p_body: Vectorthe point on this Edge, in body coordinates (optional)

#### Returns Vector

center of curvature at the given point on this Edge in body coordinates

#### Throws

for an oval shape, when

`p_body`

is undefined

- get
Centroid (): VectorBody Returns the center of the circle to use for proximity testing, in body coordinates. A circle centered at this centroid with radius

`getCentroidRadius()`

should encompass this Edge. See getCentroidRadius and getCentroidWorld.#### Returns Vector

the center of the circle to use for proximity testing, in body coordinates

- get
Centroid (): numberRadius Returns the radius of the circle to use for proximity testing. A circle centered at

`getCentroidWorld()`

with this radius should encompass this Edge. See setCentroidRadius, getCentroidRadius and getCentroidWorld.#### Returns number

the radius of the circle to use for proximity testing

- get
Centroid (): VectorWorld Returns the center of the circle to use for proximity testing, in world coordinates. A circle centered at this point with radius

`getCentroidRadius()`

should encompass this Edge. See getCentroidRadius and getCentroidBody.#### Returns Vector

the center of the circle to use for proximity testing, in world coordinates

- get
Curvature (_p_body): number Returns radius of curvature at the given point on this Edge. Radius of curvature is the radius of a circle that would give equivalent curvature at a given point on an Edge. Negative curvature means the Edge is concave at that point.

For a circle, every point on the circle has the same center and radius of curvature. But for any other curve (an oval for instance), each point on the edge can have a different center and radius of curvature.

#### Parameters

##### _p_body: Vector

the point on this Edge, in body coordinates

#### Returns number

the radius of curvature; negative means concave; returns positive infinity if this is a straight edge

#### Throws

if the point is not close to this Edge

- get
Normal (p_body): VectorBody Returns unit normal vector in body coordinates, at the given body coordinates point. Normal points outwards from the RigidBody.

**TO DO**what if the point is not on this Edge?#### Parameters

##### p_body: Vector

the point on this Edge in body coordinates

#### Returns Vector

the outwards pointing unit normal vector at the given point, in body coordinates

- get
Point (p_body): Vector[]On Edge Finds the nearest point on this Edge to the given point, returns that nearest point and the unit normal vector there. Returns

`null`

if the given point lies beyond the end point of this Edge, meaning that there is no perpendicular line to this Edge passing thru the given point.#### Parameters

##### p_body: Vector

a point near this Edge, in body coordinates

#### Returns Vector[]

a pair of Vectors: the nearest point on this Edge, and the unit normal vector at that point both in body coords; or

`null`

if there is no nearest point on this Edge.

- get
Radius (): number Returns radius of the edge. Radius is always positive, but getCurvature returns negative for concave edge.

#### Returns number

radius of the edge

- improve
Accuracy (rbc, edge): voidEdge Updates the EdgeEdgeCollision to have more accurate information based on current positions and velocities of the RigidBodys.

#### Parameters

##### rbc: RigidBodyCollision

the EdgeEdgeCollision to update

##### edge: Edge

the other Edge involved in the collision

#### Returns void

- intersection(p1_body, p2_body): null | Vector[]
Returns points on this Edge intersecting the straight line segment between the two given points (in body coordinates), or

`null`

if there is no intersection. There can be more than one point of intersection.#### Returns null | Vector[]

array of intersection points, in body coords, or

`null`

if no intersection.

- intersection
Possible (edge, swellage): boolean Rough proximity test that returns

`true`

if an intersection is possible between this Edge and the specified Edge. This is intended to do a quick rough test to eliminate obvious cases where no intersection is possible.`Swellage`

is a fudge factor which is added to the max radius of the Edges, to make the test easier to succeed.#### Parameters

##### edge: Edge

the other Edge

##### swellage: number

a fudge factor which is added to the max radius of the Edges

#### Returns boolean

whether an intersection between the Edges is possible

- is
Within (p_edge): booleanArc Returns true if the angle of the given point is within this arc. Looks at the angle from the origin to the point, compares this angle to the angle range of this arc.

#### Parameters

##### p_edge: Vector

the point of interest, in edge coordinates.

#### Returns boolean

true if the given point is within this arc.

- is
Within (p_world): booleanArc2 Returns true if the angle of the given point is within this arc. Looks at the angle from the origin to the point, compares this angle to the angle range of this arc.

#### Parameters

##### p_world: Vector

the point of interest, in world coordinates.

#### Returns boolean

true if the given point is within this arc.

- is
Within (p_edge): booleanReflected Arc Returns true if the angle of the given point is within the reflection of this arc through the center. Looks at the angle from the origin to the point, compares this angle to the angle range of the reflected arc.

Examples of reflected arcs:

- If the arc goes from 0 to pi/4, then the reflected arc goes from pi to 5 pi/4.
- If the arc goes from 0 to 3 pi/2, then the reflected arc goes from pi to 5 pi/2.

#### Parameters

##### p_edge: Vector

the point of interest, in edge coordinates.

#### Returns boolean

true if the given point is within the reflected arc.

- is
Within (p_world): booleanReflected Arc2 Returns true if the angle of the given point is within the reflection of this arc through the center. Same as isWithinReflectedArc but accepts a point in world coordinates.

#### Parameters

##### p_world: Vector

the point of interest, in world coordinates.

#### Returns boolean

true if the given point is within the reflected arc.

- max
Distance (p_body): numberTo Returns the maximum distance from the given point (in body coordinates) to any point on this Edge.

#### Parameters

##### p_body: Vector

a point in body coordinates

#### Returns number

the maximum distance from the given point (in body coordinates) to any point on this Edge

- nearest
Point (p_body): VectorBy Angle Finds the 'nearest' point (by angle) on this arc to the given point p_body.

- If the angle to p_body is within the arc, return p_body unchanged.
- If the angle to p_body is outside of the arc, return the nearest endpoint of the arc.

#### Parameters

##### p_body: Vector

the point of interest, in body coordinates

#### Returns Vector

the nearest point (by angle) on this arc to the given point, in body coordinates

- point
Offset (p_body, length): Vector Returns the point offset in the direction of this Edge's normal. The normal is taken at the point on this Edge that is closest to the given point. The point is given and returned in body coordinates. Note that the returned point might be closer to this Edge when the starting point is on the inside of the RigidBody, because the normal points outwards.

#### Parameters

##### p_body: Vector

the point near this Edge, in body coordinates

##### length: number

the distance to move the point

#### Returns Vector

the point offset in the direction of this Edge's normal, in body coordinates

- set
Centroid (value): voidRadius Sets the radius of the circle to use for proximity testing. A circle centered at

`getCentroidWorld()`

with this radius should encompass this Edge. See getCentroidRadius, getCentroidBody and getCentroidWorld.#### Parameters

##### value: number

the radius of the circle to use for proximity testing

#### Returns void

- set
Vertex2 (vertex): void Sets the finish Vertex of this Edge. Should match the start Vertex of the next Edge in the RigidBody.

#### Parameters

##### vertex: Vertex

the finish Vertex of this Edge

#### Returns void

- test
Collision (collisions, edge, time): voidEdge If there is a collision between this Edge and the given Edge, adds a RigidBodyCollision to the list. This ignores collisions with Vertexes.

#### Parameters

##### collisions: RigidBodyCollision[]

list of collisions to add to

##### edge: Edge

the other Edge

##### time: number

current simulation time

#### Returns void

`Static`

`Private`

find- find
Angle (startAngle, finishAngle, clockwise): number[]Low High Converts the start and finish angles of an arc to a pair of angles such that all of the arc is within that pair of angles.

#### Parameters

##### startAngle: number

starting angle, math convention

##### finishAngle: number

finish angle, math convention

##### clockwise: boolean

true means arc goes clockwise in math convention

#### Returns number[]

pair of angles, low and high, such that all of the arc is within that pair of angles.

`Static`

`Private`

find- find
Depth (angle, radius): number Returns 'depth of arc' which is maximum distance between arc and line connecting arc ends.

`Derivation: On unit circle, let arc start at A = [1, 0] and extend counter clockwise along circle to B = [cos theta, sin theta]. Draw a line between those two points, A and B. Let C be the midpoint of that line. C is at: C = [(1 + cos theta)/2, sin theta / 2 ]. Distance between C and (cos theta/2, sin theta/2) is the depth.`

#### Parameters

##### angle: number

angle of arc, in radians

##### radius: number

radius of circle that arc is part of

#### Returns number

maximum distance between arc and line connecting arc ends

`Static`

`Private`

is- is
Within (p_edge, angleLow, angleHigh): booleanArc #### Parameters

##### p_edge: Vector

the point of interest, in edge coordinates.

##### angleLow: number

##### angleHigh: number

#### Returns boolean

true if the given point is within this arc.

`Static`

make- make(body, vertex1, vertex2, radius, aboveRight, clockwise, outsideIsOut): CircularEdge
Creates a CircularEdge between the given Vertexes with the given radius, calculating the position of the center, and adds the edge to the given RigidBody.

Calculates the center to be at the vertex of an isoceles triangle with the given Vertexes, where the center is

`radius`

distance from each Vertex.There are two choices for where to put the center in relation to the line connecting the two given Vertexes: either above or below the line. The

`aboveRight`

parameter specifies which choice to make. For a vertical connecting line, the choice is right or left of the line.#### Parameters

##### body: RigidBody

edge will be added to this RigidBody

##### vertex1: Vertex

edge starts at this Vertex, given in body coordinates

##### vertex2: Vertex

edge finishes at this Vertex, given in body coordinates

##### radius: number

the radius of the circular arc

##### aboveRight: boolean

if true, then the center of CircularEdge is located above or right of the line connecting

`vertex1`

and`vertex2`

; if false, then center is located below or left of the connecting line.##### clockwise: boolean

direction of the arc

##### outsideIsOut: boolean

true means the outside of the circle is considered the outside of the RigidBody.

#### Returns CircularEdge

the CircularEdge that is created

#### Throws

if absolute value of

`radius`

is too small; must be greater than half the distance between the two Vertexes#### Throws

if

`vertex1`

is already connected to a 'next' Edge#### Throws

if

`vertex2`

is already connected to a 'previous' Edge

Generated using TypeDoc

A circular arc Edge belonging to a RigidBody.

## Making a CircularEdge

If you know the center of the circle use the constructor:

If you know the radius but not the center, use the static method CircularEdge.make.

Use Polygon.addCircularEdge

Use Polygon.addCircularEdge2

## Full Circle

A full circle is a special case detected by the constructor. When

`vertex1`

and`vertex2`

are at the same location, then we assume a full circle is desired. The two Vertexes need not be identical, just very close together. In this case, only one of the Vertexes is kept and there is a single Vertex and single Edge forming the circle.## Mid-Point Vertexes

See Vertex for information about why mid-point Vertexes are created on a CircularEdge and how they are used for collision checking.

## Edge Coordinates

In addition to world and body coordinates, CircularEdge also has 'edge coordinates' which takes body coordinates but shifts the origin to be the center of the circle that defines this Edge. For CircularEdge there is no change in angle between edge and body coords (unlike with an oval edge).

## About Coordinates and Angles

To avoid confusion, be clear about which of these conventions you are dealing with:

In myPhysicsLab,

simulation coordinatesusesy increases upcoordinates andangle increases counter-clockwise. Also calledworld coordinates.Javascript's

screen coordinatesusesy increases downcoordinates andangle increases clockwisein`canvas.arc()`

.The transformation between these coordinate systems is handled by CoordMap.

The table below summarizes the conventions used for angles. CircularEdge uses the

math convention for anglesshown in this table.## Details About Coordinates and Drawing

The

'y increases up'convention interacts with drawing in Javascript via CircularEdge.addPath, and DisplayShape. In DisplayShape we use the AffineTransform from the CoordMap which applies a negative factor to the vertical scale as seen in this line of code from CoordMap's constructor:The result is that all drawing happens

upside down-- if you were to draw text or an image with that AffineTransform it will appear upside down.The two conventions, simulation coords vs. screen coords, cancel out as a "double negative" when specifying

`startAngle`

,`finishAngle`

and`antiClockwise`

arguments to JavaScript's`canvas.arc()`

function.Note that for

`canvas.arc()`

, an increase in angle moves in a clockwise direction. However, because we use'y increases up'coordinates, the drawing is flipped vertically, both of these cancel, and we can use regular 'math' angles with`canvas.arc()`

.In contrast to

`canvas.arc()`

, the Javascript`Math.atan2()`

function uses standard math coordinates.