C

GeometryUtilities

This class provides useful geometric primitives and advanced geometric algorithms.
Inheritance Hierarchy

Members

No filters for this type

Static Methods

Returns whether the given points are collinear, that is, all three points lie on a common line.
static

Parameters

p: Point
The first point in the set of three points.
q: Point
The second point in the set of three points.
r: Point
The third point in the set of three points.

Return Value

boolean
true if the given points are collinear, false otherwise.
Returns whether an ellipse contains the given point.
static

Parameters

bounds: Rect
The coordinates of the bounds of the ellipse's enclosing rectangle.
point: Point
The coordinates of the point to test.
eps: number
A positive value allows for fuzzy hit testing. If the point lies outside the given object, but its distance is less than or equal to that value, it will be considered a hit.

Return Value

boolean
Whether the point lies within the ellipse
Calculates the convex hull for a set of points.
static

Parameters

points: IEnumerable<Point>
The given points for which the convex hull should be computed.

Return Value

IEnumerable<Point>
A list of Points that constitute the convex hull of the given points. The returned points are in counterclockwise order around the hull. The first point is the one with the smallest x coordinate. If two such points exist, then of these points, the one with the smallest y coordinate is chosen as the first one.

Complexity

O(n)*log(n), n := points.size()
Calculates the intersection point of an ellipse with a line defined by two points.
This will always return the intersection point that lies in the direction from inner to outer.
static

Parameters

bounds: Rect
The coordinates of the bounds of the ellipse's enclosing rectangle.
inner: Point
The coordinates of a point lying inside the ellipse.
outer: Point
The coordinates of a point lying outside the ellipse.

Return Value

Point
The intersection point iff the inner point lies inside the ellipse and an intersection point has been found, otherwise null.
Calculates the intersection point of two affine lines.
Each line is given by two points.
static

Parameters

p1: Point
One point on the first line.
p2: Point
Another point on the first line.
p3: Point
One point on the second line.
p4: Point
Another point on the second line.

Return Value

Point
The intersection point of the specified lines or null if there is no intersection.
Calculates the intersection between a line segment and an infinite ray.
The ray is described using an anchor point and a ray direction. The direction vector does not need to be normalized. To get the intersection point, do the following:
const factor = GeometryUtilities.getSegmentRayIntersection(
  l1,
  l2,
  anchor,
  ray,
)
if (factor < Number.POSITIVE_INFINITY) {
  const intersection = anchor.add(ray.multiply(factor))
}
static

Parameters

start: Point
The coordinates of the first end point of the line segment.
end: Point
The coordinates of the second end point of the line segment.
rayAnchor: Point
The coordinates of the starting point of the ray.
rayDirection: Point
The direction vector of the ray.

Return Value

number
The distance factor or Number.POSITIVE_INFINITY if the ray does not intersect the line.
Returns whether the two lines defined by the given coordinates intersect or not.
static

Parameters

p1: Point
The first point of the first line.
p2: Point
The second point of the first line.
p3: Point
The first point of the second line.
p4: Point
The second point of the second line.

Return Value

boolean
true if the two line segments intersect, false otherwise