Functions for computing the intersection between geometries such as rays, planes, triangles, and ellipsoids.
Methods
static Freedo.IntersectionTests.grazingAltitudeLocation(ray, ellipsoid) → Cartesian3
Provides the point along the ray which is nearest to the ellipsoid.
Name | Type | Description |
---|---|---|
ray |
Ray | The ray. |
ellipsoid |
Ellipsoid | The ellipsoid. |
Returns:
The nearest planetodetic point on the ray.
static Freedo.IntersectionTests.intersetRectangleWithConstraintRegion(rectangle, constraintRegions) → Number
判断矩形范围是否与限制区相交
Name | Type | Default | Description |
---|---|---|---|
rectangle |
Rectangle | 矩形范围. | |
constraintRegions |
Array.<Object> | 限制区数组. | |
constraintRegions[i].constraintRegion |
Array.<Array.<Number>> | 限制区,[[longitude0, latitude0], [longitude1, latitude1], [longitude2, latitude2], [longitude3, latitude3]...]. | |
constraintRegions[i].height |
Number |
0.0
|
optional 限制区拉平的高度. |
Returns:
返回与rectangle相交的constraintRegions索引,或者-1表示不相交.
Example:
var constraintRegions = [{
constraintRegion: [
[FreedoMath.toRadians(115.777349), FreedoMath.toRadians(38.947522)],
[FreedoMath.toRadians(115.779750), FreedoMath.toRadians(38.947522)],
[FreedoMath.toRadians(115.778750), FreedoMath.toRadians(38.947922)],
[FreedoMath.toRadians(115.779750), FreedoMath.toRadians(38.948693)],
[FreedoMath.toRadians(115.777349), FreedoMath.toRadians(38.948693)]
]
}, {
constraintRegion: [
[FreedoMath.toRadians(115.779523), FreedoMath.toRadians(38.945631)],
[FreedoMath.toRadians(115.781864), FreedoMath.toRadians(38.945631)],
[FreedoMath.toRadians(115.781864), FreedoMath.toRadians(38.946725)],
[FreedoMath.toRadians(115.779523), FreedoMath.toRadians(38.946725)]
]
}];
var rectangle = new Rectangle(west, south, east, north);
var intersetIndex = IntersectionTests.intersetRectangleWithConstraintRegion(rectangle, constraintRegions);
static Freedo.IntersectionTests.isCartographicInConstraintRegion(cartographic, mostPossibleIndex, constraintRegions) → Number
判断经纬度点是否在限制区内
Name | Type | Default | Description |
---|---|---|---|
cartographic |
Cartographic | 待判断的经纬度点. | |
mostPossibleIndex |
Number | 最可能与哪个限制区相交. | |
constraintRegions |
Array.<Object> | 限制区数组. | |
constraintRegions[i].constraintRegion |
Array.<Array.<Number>> | 限制区,[[longitude0, latitude0], [longitude1, latitude1], [longitude2, latitude2], [longitude3, latitude3]...]. | |
constraintRegions[i].height |
Number |
0.0
|
optional 限制区拉平的高度. |
Returns:
返回与cartographic相交的constraintRegions索引,或者-1表示不相交.
Example:
var constraintRegions = [{
constraintRegion: [
[FreedoMath.toRadians(115.777349), FreedoMath.toRadians(38.947522)],
[FreedoMath.toRadians(115.779750), FreedoMath.toRadians(38.947522)],
[FreedoMath.toRadians(115.778750), FreedoMath.toRadians(38.947922)],
[FreedoMath.toRadians(115.779750), FreedoMath.toRadians(38.948693)],
[FreedoMath.toRadians(115.777349), FreedoMath.toRadians(38.948693)]
]
}, {
constraintRegion: [
[FreedoMath.toRadians(115.779523), FreedoMath.toRadians(38.945631)],
[FreedoMath.toRadians(115.781864), FreedoMath.toRadians(38.945631)],
[FreedoMath.toRadians(115.781864), FreedoMath.toRadians(38.946725)],
[FreedoMath.toRadians(115.779523), FreedoMath.toRadians(38.946725)]
]
}];
var cartographic = new Cartographic(FreedoMath.toRadians(115.78), FreedoMath.toRadians(38.946));
var intersetIndex = IntersectionTests.isCartographicInConstraintRegion(cartographic, -1, constraintRegions);
static Freedo.IntersectionTests.lineSegmentPlane(endPoint0, endPoint1, plane, result) → Cartesian3
Computes the intersection of a line segment and a plane.
Name | Type | Description |
---|---|---|
endPoint0 |
Cartesian3 | An end point of the line segment. |
endPoint1 |
Cartesian3 | The other end point of the line segment. |
plane |
Plane | The plane. |
result |
Cartesian3 | optional The object onto which to store the result. |
Returns:
The intersection point or undefined if there is no intersection.
Example:
const origin = Freedo.Cartesian3.fromDegrees(-75.59777, 40.03883);
const normal = ellipsoid.geodeticSurfaceNormal(origin);
const plane = Freedo.Plane.fromPointNormal(origin, normal);
const p0 = new Freedo.Cartesian3(...);
const p1 = new Freedo.Cartesian3(...);
// find the intersection of the line segment from p0 to p1 and the tangent plane at origin.
const intersection = Freedo.IntersectionTests.lineSegmentPlane(p0, p1, plane);
static Freedo.IntersectionTests.lineSegmentSphere(p0, p1, sphere, result) → Interval
Computes the intersection points of a line segment with a sphere.
Name | Type | Description |
---|---|---|
p0 |
Cartesian3 | An end point of the line segment. |
p1 |
Cartesian3 | The other end point of the line segment. |
sphere |
BoundingSphere | The sphere. |
result |
Interval | optional The result onto which to store the result. |
Returns:
The interval containing scalar points along the ray or undefined if there are no intersections.
static Freedo.IntersectionTests.lineSegmentTriangle(v0, v1, p0, p1, p2, cullBackFaces, result) → Cartesian3
Computes the intersection of a line segment and a triangle.
Name | Type | Default | Description |
---|---|---|---|
v0 |
Cartesian3 | The an end point of the line segment. | |
v1 |
Cartesian3 | The other end point of the line segment. | |
p0 |
Cartesian3 | The first vertex of the triangle. | |
p1 |
Cartesian3 | The second vertex of the triangle. | |
p2 |
Cartesian3 | The third vertex of the triangle. | |
cullBackFaces |
Boolean |
false
|
optional
If true , will only compute an intersection with the front face of the triangle
and return undefined for intersections with the back face. |
result |
Cartesian3 |
optional
The Cartesian3 onto which to store the result. |
Returns:
The intersection point or undefined if there is no intersections.
static Freedo.IntersectionTests.rayEllipsoid(ray, ellipsoid) → Interval
Computes the intersection points of a ray with an ellipsoid.
Name | Type | Description |
---|---|---|
ray |
Ray | The ray. |
ellipsoid |
Ellipsoid | The ellipsoid. |
Returns:
The interval containing scalar points along the ray or undefined if there are no intersections.
static Freedo.IntersectionTests.rayPlane(ray, plane, result) → Cartesian3
Computes the intersection of a ray and a plane.
Name | Type | Description |
---|---|---|
ray |
Ray | The ray. |
plane |
Plane | The plane. |
result |
Cartesian3 | optional The object onto which to store the result. |
Returns:
The intersection point or undefined if there is no intersections.
static Freedo.IntersectionTests.raySphere(ray, sphere, result) → Interval
Computes the intersection points of a ray with a sphere.
Name | Type | Description |
---|---|---|
ray |
Ray | The ray. |
sphere |
BoundingSphere | The sphere. |
result |
Interval | optional The result onto which to store the result. |
Returns:
The interval containing scalar points along the ray or undefined if there are no intersections.
static Freedo.IntersectionTests.rayTriangle(ray, p0, p1, p2, cullBackFaces, result) → Cartesian3
Computes the intersection of a ray and a triangle as a Cartesian3 coordinate.
Implements Fast Minimum Storage Ray/Triangle Intersection by Tomas Moller and Ben Trumbore.
Name | Type | Default | Description |
---|---|---|---|
ray |
Ray | The ray. | |
p0 |
Cartesian3 | The first vertex of the triangle. | |
p1 |
Cartesian3 | The second vertex of the triangle. | |
p2 |
Cartesian3 | The third vertex of the triangle. | |
cullBackFaces |
Boolean |
false
|
optional
If true , will only compute an intersection with the front face of the triangle
and return undefined for intersections with the back face. |
result |
Cartesian3 |
optional
The Cartesian3 onto which to store the result. |
Returns:
The intersection point or undefined if there is no intersections.
Computes the intersection of a ray and a triangle as a parametric distance along the input ray. The result is negative when the triangle is behind the ray.
Implements Fast Minimum Storage Ray/Triangle Intersection by Tomas Moller and Ben Trumbore.
Name | Type | Default | Description |
---|---|---|---|
ray |
Ray | The ray. | |
p0 |
Cartesian3 | The first vertex of the triangle. | |
p1 |
Cartesian3 | The second vertex of the triangle. | |
p2 |
Cartesian3 | The third vertex of the triangle. | |
cullBackFaces |
Boolean |
false
|
optional
If true , will only compute an intersection with the front face of the triangle
and return undefined for intersections with the back face. |
Returns:
The intersection as a parametric distance along the ray, or undefined if there is no intersection.
Computes the intersection of a triangle and a plane
Name | Type | Description |
---|---|---|
p0 |
Cartesian3 | First point of the triangle |
p1 |
Cartesian3 | Second point of the triangle |
p2 |
Cartesian3 | Third point of the triangle |
plane |
Plane | Intersection plane |
Returns:
An object with properties
positions
and indices
, which are arrays that represent three triangles that do not cross the plane. (Undefined if no intersection exists)
Example:
const origin = Freedo.Cartesian3.fromDegrees(-75.59777, 40.03883);
const normal = ellipsoid.geodeticSurfaceNormal(origin);
const plane = Freedo.Plane.fromPointNormal(origin, normal);
const p0 = new Freedo.Cartesian3(...);
const p1 = new Freedo.Cartesian3(...);
const p2 = new Freedo.Cartesian3(...);
// convert the triangle composed of points (p0, p1, p2) to three triangles that don't cross the plane
const triangles = Freedo.IntersectionTests.trianglePlaneIntersection(p0, p1, p2, plane);