pex-geom
v3.1.2
Published
Geometry intersection and bounding volume helpers for PEX.
Readme
pex-geom
Geometry intersection and bounding volume helpers for PEX.
Installation
npm install pex-geomUsage
import { ray, aabb } from "pex-geom";
const box = aabb.fromPoints([
[-1, -1, -1],
[1, 1, 1],
]);
const intersect = ray.hitTestAABB(
[
[0, 0, 0],
[0, 1, 0],
],
box
);
console.log(intersect);
// => trueAPI
Modules
Typedefs
pex-geom
pex-geom.aabb : aabb
Kind: static property of pex-geom
pex-geom.plane : plane
Kind: static property of pex-geom
pex-geom.ray : ray
Kind: static property of pex-geom
pex-geom.rect : rect
Kind: static property of pex-geom
aabb
- aabb
- .create() ⇒ AABB
- .empty(a) ⇒ Rect
- .copy(a) ⇒ AABB
- .set(a, b) ⇒ AABB
- .isEmpty(a) ⇒ boolean
- .fromPoints(a, points) ⇒ AABB
- .getCorners(a, [points]) ⇒ Array.<module:pex-math~Vec3>
- .center(a, out) ⇒ module:pex-math~Vec3
- .size(a, out) ⇒ module:pex-math~Vec3
- .containsPoint(a, p) ⇒ boolean
- .includeAABB(a, b) ⇒ AABB
- .includePoint(a, p, [i]) ⇒ module:pex-math~Vec3
- .toString(a, [precision]) ⇒ string
aabb.create() ⇒ AABB
Creates a new bounding box.
Kind: static method of aabb
aabb.empty(a) ⇒ Rect
Reset a bounding box.
Kind: static method of aabb
| Param | Type | | ----- | -------------------------- | | a | AABB |
aabb.copy(a) ⇒ AABB
Copies a bounding box.
Kind: static method of aabb
| Param | Type | | ----- | -------------------------- | | a | AABB |
aabb.set(a, b) ⇒ AABB
Sets a bounding box to another.
Kind: static method of aabb
| Param | Type | | ----- | -------------------------- | | a | AABB | | b | AABB |
aabb.isEmpty(a) ⇒ boolean
Checks if a bounding box is empty.
Kind: static method of aabb
| Param | Type | | ----- | -------------------------- | | a | AABB |
aabb.fromPoints(a, points) ⇒ AABB
Updates a bounding box from a list of points.
Kind: static method of aabb
| Param | Type | | ------ | -------------------------------------------------------------------------------------------- | | a | AABB | | points | Array.<module:pex-math~~Vec3> | module:pex-math~~TypedArray |
aabb.getCorners(a, [points]) ⇒ Array.<module:pex-math~Vec3>
Returns a list of 8 points from a bounding box.
Kind: static method of aabb
| Param | Type | | -------- | ----------------------------------------------- | | a | AABB | | [points] | Array.<module:pex-math~Vec3> |
aabb.center(a, out) ⇒ module:pex-math~Vec3
Returns the center of a bounding box.
Kind: static method of aabb
| Param | Type | | ----- | --------------------------------- | | a | AABB | | out | module:pex-math~Vec3 |
aabb.size(a, out) ⇒ module:pex-math~Vec3
Returns the size of a bounding box.
Kind: static method of aabb
| Param | Type | | ----- | --------------------------------- | | a | AABB | | out | module:pex-math~Vec3 |
aabb.containsPoint(a, p) ⇒ boolean
Checks if a point is inside a bounding box.
Kind: static method of aabb
| Param | Type | | ----- | --------------------------------- | | a | AABB | | p | module:pex-math~Vec3 |
aabb.includeAABB(a, b) ⇒ AABB
Includes a bounding box in another.
Kind: static method of aabb
| Param | Type | | ----- | -------------------------- | | a | AABB | | b | AABB |
aabb.includePoint(a, p, [i]) ⇒ module:pex-math~Vec3
Includes a point in a bounding box.
Kind: static method of aabb
| Param | Type | Default | Description | | ----- | --------------------------------- | -------------- | ------------------------- | | a | AABB | | | | p | module:pex-math~Vec3 | | | | [i] | number | 0 | Offset in the point array |
aabb.toString(a, [precision]) ⇒ string
Prints a bounding box to a string.
Kind: static method of aabb
| Param | Type | Default | | ----------- | -------------------------- | -------------- | | a | AABB | | | [precision] | number | 4 |
plane
- plane
- .Side : enum
- .create() ⇒ Plane
- .side(plane, point) ⇒ number
- .toString(a, [precision]) ⇒ string
plane.Side : enum
Enum for different side values
Kind: static enum of plane Read only: true Properties
| Name | Type | Description | | -------- | ------------------- | ------------------------------------------------- | | OnPlane | number | Point lies on the plane | | Same | number | Point is on the same side as the plane normal | | Opposite | number | Point is on the opposite side of the plane normal |
plane.create() ⇒ Plane
Creates a new plane
Kind: static method of plane
plane.side(plane, point) ⇒ number
Returns on which side a point is.
Kind: static method of plane
| Param | Type | | ----- | --------------------------------- | | plane | Plane | | point | module:pex-math~Vec3 |
plane.toString(a, [precision]) ⇒ string
Prints a plane to a string.
Kind: static method of plane
| Param | Type | Default | | ----------- | ---------------------------- | -------------- | | a | Plane | | | [precision] | number | 4 |
ray
- ray
- .Intersections : enum
- .create() ⇒ Ray
- .hitTestPlane(ray, plane, out) ⇒ number
- .hitTestTriangle(ray, triangle, out) ⇒ number
- .hitTestAABB(ray, aabb) ⇒ boolean
- .intersectsAABB()
- .toString(a, [precision]) ⇒ string
ray.Intersections : enum
Enum for different intersections values
Kind: static enum of ray Read only: true Properties
| Name | Type | Description | | ------------------ | ------------------- | ------------------------------------------- | | Intersect | number | Ray intersects the target | | NoIntersect | number | Ray does not intersect the target | | SamePlane | number | Ray lies on the same plane as the target | | Parallel | number | Ray is parallel to the target | | TriangleDegenerate | number | Triangle has zero area and cannot be tested |
ray.create() ⇒ Ray
Creates a new ray
Kind: static method of ray
ray.hitTestPlane(ray, plane, out) ⇒ number
Determines if a ray intersect a plane and set intersection point
Kind: static method of ray See: https://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld017.htm
| Param | Type | | ----- | --------------------------------- | | ray | Ray | | plane | Plane | | out | module:pex-math~Vec3 |
ray.hitTestTriangle(ray, triangle, out) ⇒ number
Determines if a ray intersect a triangle and set intersection point
Kind: static method of ray See: https://web.archive.org/web/20200701173519/http://geomalgorithms.com/a06-_intersect-2.html#intersect3D_RayTriangle()
| Param | Type | | -------- | ---------------------------------- | | ray | Ray | | triangle | Triangle | | out | module:pex-math~Vec3 |
ray.hitTestAABB(ray, aabb) ⇒ boolean
Determines if a ray intersect an AABB bounding box
Kind: static method of ray See: http://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms
| Param | Type | | ----- | -------------------------- | | ray | Ray | | aabb | AABB |
ray.intersectsAABB()
Alias for hitTestAABB
Kind: static method of ray
ray.toString(a, [precision]) ⇒ string
Prints a plane to a string.
Kind: static method of ray
| Param | Type | Default | | ----------- | ------------------------ | -------------- | | a | Ray | | | [precision] | number | 4 |
rect
- rect
- .create() ⇒ Rect
- .empty(a) ⇒ Rect
- .copy(a) ⇒ Rect
- .set(a, b) ⇒ Rect
- .isEmpty(a) ⇒ boolean
- .fromPoints(a, points) ⇒ Rect
- .getCorners(a, points) ⇒ Array.<module:pex-math~Vec2>
- .scale(a, n) ⇒ Rect
- .setSize(a, size) ⇒ Rect
- .size(a, out) ⇒ module:pex-math~Vec2
- .width(a) ⇒ number
- .height(a) ⇒ number
- .aspectRatio(a) ⇒ number
- .setPosition(a, p) ⇒ Rect
- .center(a, out) ⇒ Rect
- .containsPoint(a, p) ⇒ boolean
- .containsRect(a, b) ⇒ boolean
- .includePoint(a, p) ⇒ Rect
- .includeRect(a, b) ⇒ Rect
- .mapPoint(a, p) ⇒ module:pex-math~Vec2
- .clampPoint(a, p) ⇒ module:pex-math~Vec2
- .toString(a, [precision]) ⇒ string
rect.create() ⇒ Rect
Creates a new rectangle.
Kind: static method of rect
rect.empty(a) ⇒ Rect
Reset a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.copy(a) ⇒ Rect
Copies a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.set(a, b) ⇒ Rect
Sets a rectangle to another.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect | | b | Rect |
rect.isEmpty(a) ⇒ boolean
Checks if a rectangle is empty.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.fromPoints(a, points) ⇒ Rect
Updates a rectangle from a list of points.
Kind: static method of rect
| Param | Type | | ------ | -------------------------------------------------------------------------------------------- | | a | Rect | | points | Array.<module:pex-math~~Vec2> | module:pex-math~~TypedArray |
rect.getCorners(a, points) ⇒ Array.<module:pex-math~Vec2>
Returns a list of 4 points from a rectangle.
Kind: static method of rect
| Param | Type | | ------ | ----------------------------------------------- | | a | Rect | | points | Array.<module:pex-math~Vec2> |
rect.scale(a, n) ⇒ Rect
Scales a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect | | n | number |
rect.setSize(a, size) ⇒ Rect
Sets the size of a rectangle using width and height.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | size | module:pex-math~Vec2 |
rect.size(a, out) ⇒ module:pex-math~Vec2
Returns the size of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | out | module:pex-math~Vec2 |
rect.width(a) ⇒ number
Returns the width of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.height(a) ⇒ number
Returns the height of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.aspectRatio(a) ⇒ number
Returns the aspect ratio of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect |
rect.setPosition(a, p) ⇒ Rect
Sets the position of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | p | module:pex-math~Vec2 |
rect.center(a, out) ⇒ Rect
Returns the center of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | out | module:pex-math~Vec2 |
rect.containsPoint(a, p) ⇒ boolean
Checks if a point is inside a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | p | module:pex-math~Vec2 |
rect.containsRect(a, b) ⇒ boolean
Checks if a rectangle is inside another rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect | | b | Rect |
rect.includePoint(a, p) ⇒ Rect
Includes a point in a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | p | module:pex-math~Vec2 |
rect.includeRect(a, b) ⇒ Rect
Includes a rectangle in another rectangle.
Kind: static method of rect
| Param | Type | | ----- | -------------------------- | | a | Rect | | b | Rect |
rect.mapPoint(a, p) ⇒ module:pex-math~Vec2
Maps a point into the dimensions of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | p | module:pex-math~Vec2 |
rect.clampPoint(a, p) ⇒ module:pex-math~Vec2
Clamps a point into the dimensions of a rectangle.
Kind: static method of rect
| Param | Type | | ----- | --------------------------------- | | a | Rect | | p | module:pex-math~Vec2 |
rect.toString(a, [precision]) ⇒ string
Prints a rect to a string.
Kind: static method of rect
| Param | Type | Default | | ----------- | -------------------------- | -------------- | | a | Rect | | | [precision] | number | 4 |
AABB : Array.<Array.<number>>
An axis-aligned bounding box defined by two min and max 3D points (eg. [[minX, minY, minZ], [maxX, maxY, maxZ]]).
Kind: global typedef
Plane : Array.<Array.<number>>
A plane defined by a 3D point and a normal vector perpendicular to the plane’s surface (eg. [[pointX, pointY, pointZ], [normalX, normalY, normalZ]]).
Kind: global typedef
Ray : Array.<Array.<number>>
A ray defined by a starting 3D point origin and a 3D direction vector (eg. [[originX, originY, originZ], [directionX, directionY, directionZ]).
Kind: global typedef
Rect : Array.<Array.<number>>
A rectangle defined by two diagonally opposite 2D points (eg. [[minX, minY], [maxX, maxY]]).
Kind: global typedef
Triangle : Array.<Array.<number>>
A triangle defined by three 3D points.
Kind: global typedef
License
MIT. See license file.
