# Interface Vertex

A Vertex is a point on an Edge in a RigidBody, in body coordinates of the RigidBody. A Vertex can be at the end-point of the Edge, or at a mid-point of the Edge. An end-point Vertex is connected to two Edges which are called the 'previous' and 'next' Edges. A mid-point Vertex is connected to only a single Edge, which is considered to be both the 'previous' and 'next' Edge in that case.

See RigidBody, and Edge.

## Decorated Mid-Point Vertexes

See also the section on Decorated Vertexes in the 2D Physics Engine Overview.

We add 'decorated mid-point Vertexes' along a curved edge to help with collision and contact detection.

In collision detection, we look at both the current and previous position of the bodies to guess how the bodies moved over the last time step. For a potential Vertex/Edge collision, we assume the Vertex moved along the straight line between its previous and current position, and look for the intersection of that line with the Edge.

For an Edge/Edge collision, when one of the Edges is curved, it is more difficult to detect collisions and contacts. For Edge/Edge collision testing we only use the current position of the Edges, instead of looking at how the Edges moved over time. There are cases where two rapidly moving curved edges can pass entirely thru each other in a single time step and so the Edge/Edge code will not detect the collision. The solution is to add Vertexes along the curved Edge, and rely on the regular Vertex/Edge collision checking.

We refer to these as 'mid-point' or 'decorated' Vertexes to distinguish them from the 'end-point' Vertexes at the end-points of line segments. See isEndPoint. The number of decorated Vertexes can be controlled by a spacing parameter when making a curved Edge.

What typically happens for a collision involving a curved Edge and another Edge is:

1. The mid-point Vertexes indicate there is a collision; the Edge/Edge tests might also indicate a collision.

2. After backing up and getting close to – but just before – the moment of collision, the Edge/Edge collision will have the smallest gap among all the detected contacts or collisions, and will therefore supersede any decorated Vertex/Edge collisions or contacts. The Edge/Edge collision gives better accuracy.

interface Vertex {
getCurvature(): number;
getEdge1(): Edge;
getEdge2(): Edge;
getID(): number;
highlight(): void;
isEndPoint(): boolean;
locBody(): Vector;
locBodyX(): number;
locBodyY(): number;
safeGetEdge2(): null | Edge;
setEdge1(edge): void;
setEdge2(edge): void;
toStringShort(): string;
}

## Methods

• Returns the radius of curvature of the Edge at the Vertex's location. If the Vertex is between two Edges, returns the radius of curvature with smaller absolute value. Negative curvature means the Edge is concave at that point.

#### Returns number

radius of curvature of Edge at the Vertex, negative means concave

• Returns the 'previous' Edge that this Vertex is connected to.

#### Returns Edge

the 'previous' Edge that this Vertex is connected to.

#### Throws

if edge1 not yet set for this Vertex

• Returns the 'next' Edge that this Vertex is connected to.

#### Returns Edge

the 'next' Edge that this Vertex is connected to.

#### Throws

if edge2 not yet set for this Vertex

• Returns an identity number unique for each Vertex, for debugging.

#### Returns number

an identity number unique for each Vertex, for debugging.

• Returns true if this is a Vertex at the end of an Edge; returns false if this is a 'decorated mid-point' Vertex.

#### Returns boolean

true if this is a Vertex at the end of an Edge; returns false if this is a 'decorated mid-point' Vertex.

• Returns the location of this Vertex in body coords of its RigidBody.

#### Returns Vector

location of this Vertex in body coords of its RigidBody

• Returns the horizontal location of this Vertex in body coords of its RigidBody.

#### Returns number

location of this Vertex in body coords of its RigidBody

• Returns the vertical location of this Vertex in body coords of its RigidBody.

#### Returns number

location of this Vertex in body coords of its RigidBody

• Returns the next edge, or null if not yet assigned.

#### Returns null | Edge

edge the next edge, or `null` if not yet assigned.

• Sets the 'previous' Edge that this Vertex is connected to.

#### Parameters

• ##### edge: Edge

the 'previous' Edge that this Vertex is connected to.

#### Throws

if this Vertex was already connected to a previous Edge

• Sets the 'next' Edge that this Vertex is connected to.

#### Parameters

• ##### edge: Edge

the 'next' Edge that this Vertex is connected to

#### Throws

if this Vertex was already connected to a next Edge

• Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling `toStringShort` on that other object. For example, calling `toStringShort()` on a DisplayShape might return something like this:

``````DisplayShape{polygon:Polygon{'chain3'}}
``````

#### Returns string

a minimal string representation of this object.

Generated using TypeDoc