TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class Geometric in Tinman.Core.Math

Helper class for computing geometric intersections.

static class Geometric  

Public / Methods

AngleAdd

Add the given cosine angles.

[Pure]
public static method AngleAdd (float64 a, float64 b)
type float64
params a Cosine of first angle to add.
  b Cosine of second angle to add.
returns [-1..1] Cosine of added angle.

Remarks:

This method computes cos(acos(a) + acos(b)) without trigonometric functions: a * b - sqrt(1 - a^2) * sqrt(1 - b^2)

AngleFlip

Flips the given angle at 90°.

[Pure]
public static method AngleFlip (float64 a)
type float64
params a Cosine of angle to flip.
returns [0..1] Cosine of flipped angle.

Remarks:

This method computes cos(90° - acos(a)) without trigonometric functions: sqrt(1 - a^2)

AngleSub

Subtracts the given cosine angles.

[Pure]
public static method AngleSub (float64 a, float64 b)
type float64
params a Cosine of first angle to subtract in the range.
  b Cosine of second angle to subtract.
returns [-1..1] Cosine of subtracted angle.

Remarks:

This method computes cos(acos(a) - acos(b)) without trigonometric functions: a * b + sqrt(1 - a^2) * sqrt(1 - b^2)

For common values of a, the formula reduces to these forms:

Area

Computes the area of the given triangle.

[Pure]
public static method Area (Vec2D v1, Vec2D v2, Vec2D v3)
type float64
params v1 First vertex of triangle.
  v2 Second vertex of triangle.
  v3 Third vertex of triangle.
returns The signed area of the triangle.

Computes the area of the given triangle.

[Pure]
public static method Area (Vec3D v1, Vec3D v2, Vec3D v3)
type float64
params v1 First vertex of triangle.
  v2 Second vertex of triangle.
  v3 Third vertex of triangle.
returns [>=0] The area of the triangle.

Computes the signed area of the given simple polygon.

public static method Area (Vec2D[] v, int32 a, int32 b)
type float64
params v [not-null] The polygon vertices.
  a [0..v.Length-1] Index of first polygon vertex.
  b [0..v.Length-1] Index of last polygon vertex.
returns The signed area of the simple polygon.

Remarks:

The polygon is defined as follows:

v[a    ] := first polygon vertex
v[a + n] := n-th polygon vertex
v[b    ] := last polygon vertex (not equal to first)

where b - a >= 2
      b - a >= n >= 0
Inverting the order of the polygon vertices will flip the sign of the area value. For a standard Cartesian coordinate system (X-axis points to the right, Y-axis points upwards), clockwise polygons have negative area values and counter-clockwise polygons have positive area values.


Computes the area of the given triangle.

[Pure]
public static method Area (float64 x1, float64 y1, float64 x2, float64 y2, float64 x3, float64 y3)
type float64
params x1 X-coordinate of first vertex of triangle.
  y1 Y-coordinate of first vertex of triangle.
  x2 X-coordinate of second vertex of triangle.
  y2 Y-coordinate of second vertex of triangle.
  x3 X-coordinate of third vertex of triangle.
  y3 Y-coordinate of third vertex of triangle.
returns The signed area of the triangle.

Computes the area of the given triangle.

[Pure]
public static method Area (float64 x1, float64 y1, float64 z1, float64 x2, float64 y2, float64 z2, float64 x3, float64 y3, float64 z3)
type float64
params x1 X-coordinate of first vertex of triangle.
  y1 Y-coordinate of first vertex of triangle.
  z1 Z-coordinate of first vertex of triangle.
  x2 X-coordinate of second vertex of triangle.
  y2 Y-coordinate of second vertex of triangle.
  z2 Z-coordinate of second vertex of triangle.
  x3 X-coordinate of third vertex of triangle.
  y3 Y-coordinate of third vertex of triangle.
  z3 Z-coordinate of third vertex of triangle.
returns [>=0] The area of the triangle.

CartesianToSpherical

Converts the given cartesian coordinates into spherical coordinates.

[Pure]
public static method CartesianToSpherical (Vec3D cartesian)
type Vec3D
params cartesian The cartesian coordinates.
returns The spherical coordinates.

Remarks:

The components of the returned vector have the following semantic:

spherical.X := radius (distance to origin).
spherical.Y := azimuthal angle (angle from positive X-axis in radians) in the range [-PI..PI].
spherical.Z := polar angle (angle from positive Z-axis in radians) in the range [0..PI].


Converts the given cartesian coordinates into spherical coordinates.

[Pure]
public static method CartesianToSpherical (float64 x, float64 y, float64 z)
type Vec3D
params x The cartesian X-coordinate.
  y The cartesian Y-coordinate.
  z The cartesian Z-coordinate.
returns The spherical coordinates.

Remarks:

The components of the returned vector have the following semantic:

spherical.X := radius (distance to origin).
spherical.Y := azimuthal angle (angle from positive X-axis in radians) in the range [-PI..PI].
spherical.Z := polar angle (angle from positive Z-axis in radians) in the range [0..PI].

CheckIntersectionOfLineSegments

Checks if the given line segments intersect.

[Pure]
public static method CheckIntersectionOfLineSegments (Vec2D v1, Vec2D v2, Vec2D v3, Vec2D v4)
type bool
params v1 Start of first line segment.
  v2 End of first line segment.
  v3 Start of second line segment.
  v4 End of second line segment.
returns true if the line segments intersect, false if not.

Checks if the given line segments intersect.

[Pure]
public static method CheckIntersectionOfLineSegments (float64 x1, float64 y1, float64 x2, float64 y2, float64 x3, float64 y3, float64 x4, float64 y4)
type bool
params x1 X-coordinate of start of first line segment.
  y1 Y-coordinate of start of first line segment.
  x2 X-coordinate of end of first line segment.
  y2 Y-coordinate of end of first line segment.
  x3 X-coordinate of start of second line segment.
  y3 X-coordinate of start of second line segment.
  x4 X-coordinate of end of second line segment.
  y4 X-coordinate of end of second line segment.
returns true if the line segments intersect, false if not.

DistanceLineToLine

Computes the pair of nearest points on two lines.

[Pure]
public static method DistanceLineToLine (Vec3D s1, Vec3D v1, Vec3D s2, Vec3D v2)
type Vec2D
params s1 Point on first line.
  v1 Direction vector of first line.
  s2 Point on second line.
  v2 Direction vector of second line.
returns The coefficient vector for computing the two nearest points on both lines:
p1 = s1 + v1 * X
p2 = s2 + v2 * Y

DistancePointToHorizon

Computes the distance from the given point to the horizon circle on a sphere centered at the coordinate origin and having the given radius.

[Pure]
public static method DistancePointToHorizon (Vec3D point, float64 radius)
type float64
params point The point coordinates.
  radius [>0] The sphere radius.
returns [>=0] The distance to the horizon, in terrain-space.

DistancePointToLine

Returns the distance of the given point to the specified line.

public static method DistancePointToLine (Vec3D p, Vec3D s, Vec3D v)
type Vec3D
params p The point.
  s A point on the line.
  v Direction vector of the line.
returns The point on the line that is nearest to p.

DistancePointToLineSegment

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (Vec2D a, Vec2D b)
type float64
params a Start point of line segment.
  b End point of line segment.
returns The distance of the point on line segment from where the distance has been computed.

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (Vec3D a, Vec3D b)
type float64
params a Start point of line segment.
  b End point of line segment.
returns The distance of the point on line segment from where the distance has been computed.

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (Vec2D a, Vec2D b, out Vec2D result)
params a Start point of line segment.
  b End point of line segment.
  result The distance (see X) and weight of point on line segment from where the distance has been computed (see Y, 0 = start point, 1 = end point).

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (Vec3D a, Vec3D b, out Vec2D result)
params a Start point of line segment.
  b End point of line segment.
  result The distance (see X) and weight of point on line segment from where the distance has been computed (see Y, 0 = start point, 1 = end point).

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (float64 ax, float64 ay, float64 bx, float64 by)
type float64
params ax X-coordinate of start point of line segment.
  ay Y-coordinate of start point of line segment.
  bx X-coordinate of end point of line segment.
  by Y-coordinate of end point of line segment.
returns The distance of the point on line segment from where the distance has been computed.

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (float64 ax, float64 ay, float64 bx, float64 by, out Vec2D result)
params ax X-coordinate of start point of line segment.
  ay Y-coordinate of start point of line segment.
  bx X-coordinate of end point of line segment.
  by Y-coordinate of end point of line segment.
  result The distance (see X) and weight of point on line segment from where the distance has been computed (see Y, 0 = start point, 1 = end point).

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (float64 ax, float64 ay, float64 az, float64 bx, float64 by, float64 bz)
type float64
params ax X-coordinate of start point of line segment.
  ay Y-coordinate of start point of line segment.
  az Z-coordinate of start point of line segment.
  bx X-coordinate of end point of line segment.
  by Y-coordinate of end point of line segment.
  bz Z-coordinate of end point of line segment.
returns The distance of the point on line segment from where the distance has been computed.

Computes the distance between the point (0|0) and the given line segment.

[Pure]
public static method DistancePointToLineSegment (float64 ax, float64 ay, float64 az, float64 bx, float64 by, float64 bz, out Vec2D result)
params ax X-coordinate of start point of line segment.
  ay Y-coordinate of start point of line segment.
  az Z-coordinate of start point of line segment.
  bx X-coordinate of end point of line segment.
  by Y-coordinate of end point of line segment.
  bz Z-coordinate of end point of line segment.
  result The distance (see X) and weight of point on line segment from where the distance has been computed (see Y, 0 = start point, 1 = end point).

DistancePointToTriangle

Computes the distance between a triangle and the given point.

[Pure]
public static method DistancePointToTriangle (Vec3D point, Vec3D a, Vec3D b, Vec3D c)
type float64
params point The point.
  a First triangle vertex.
  b Second triangle vertex.
  c Third triangle vertex.
returns The positive distance of -1 if the distance must be computed from one of the triangle edges or one of the triangle corners.

IntersectionOfLineSegments

Computes the intersection of the given line segments.

[Pure]
public static method IntersectionOfLineSegments (Vec2D v1, Vec2D v2, Vec2D v3, Vec2D v4)
type Vec2D
params v1 Start of first line segment.
  v2 End of first line segment.
  v3 Start of second line segment.
  v4 End of second line segment.
returns The intersection point or Undefined if the line segments are parallel or do not intersect.

Computes the intersection of the given line segments.

[Pure]
public static method IntersectionOfLineSegments (float64 x1, float64 y1, float64 x2, float64 y2, float64 x3, float64 y3, float64 x4, float64 y4)
type Vec2D
params x1 X-coordinate of start of first line segment.
  y1 Y-coordinate of start of first line segment.
  x2 X-coordinate of end of first line segment.
  y2 Y-coordinate of end of first line segment.
  x3 X-coordinate of start of second line segment.
  y3 Y-coordinate of start of second line segment.
  x4 X-coordinate of end of second line segment.
  y4 Y-coordinate of end of second line segment.
returns The intersection point or Undefined if the line segments are parallel or do not intersect.

IntersectionOfRayAndPlane

Computes the intersection between the given ray and plane.

[Pure]
public static method IntersectionOfRayAndPlane (Vec3D origin, Vec3D direction, Vec3D normal, float64 dot)
type Vec3D
params origin The ray origin.
  direction The ray direction.
  normal Normal vector of plane.
  dot Dot product of normal with any point in the plane.
returns The intersection point or Undefined if there is no intersection.

IntersectionOfRayAndSphere

Computes the intersection between the given ray and sphere.

[Pure]
public static method IntersectionOfRayAndSphere (Vec3D origin, Vec3D direction, float64 radius, int32 sign = 0)
type Vec3D
params origin The ray origin.
  direction The ray direction.
  radius Sphere radius (center lies at coordinate origin).
  sign Determines which intersection point to return:
<0: point behind origin
=0: any point
>0: point in front of origin
returns The intersection point that is nearest origin or Undefined.

IntersectionOfRayAndTriangle

[Pure]
public static method IntersectionOfRayAndTriangle (Vec3D origin, Vec3D direction, Vec3D v1, Vec3D v2, Vec3D v3, out Vec3D point, out Vec3D weights)
type bool
params origin
  direction
  v1
  v2
  v3
  point
  weights

IsConcave

Checks if the given quadrilateral is concave.

public static method IsConcave (Vec2D a, Vec2D b, Vec2D c, Vec2D d)
type bool
params a First vertex.
  b Second vertex.
  c Third vertex.
  d Fourth vertex.
returns true if the quadrilateral is concave, false if it is convex.

Length

Computes the length of the given vector.

[Pure]
public static method Length (float64 x, float64 y)
type float64
params x X-component of vector.
  y Y-component of vector.
returns The vector length.

Computes the length of the given vector.

[Pure]
public static method Length (float32 x, float32 y)
type float32
params x X-component of vector.
  y Y-component of vector.
returns The vector length.

Computes the length of the given vector.

[Pure]
public static method Length (float64 x, float64 y, float64 z)
type float64
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The vector length.

Computes the length of the given vector.

[Pure]
public static method Length (float32 x, float32 y, float32 z)
type float32
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The vector length.

LengthSqr

Computes the square length of the given vector.

[Pure]
public static method LengthSqr (float64 x, float64 y)
type float64
params x X-component of vector.
  y Y-component of vector.
returns The square vector length.

Computes the square length of the given vector.

[Pure]
public static method LengthSqr (float32 x, float32 y)
type float32
params x X-component of vector.
  y Y-component of vector.
returns The square vector length.

Computes the square length of the given vector.

[Pure]
public static method LengthSqr (float64 x, float64 y, float64 z)
type float64
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The square vector length.

Computes the square length of the given vector.

[Pure]
public static method LengthSqr (float32 x, float32 y, float32 z)
type float32
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The square vector length.

Lerp

Linearly interpolates between the given vectors.

[Pure]
public static method Lerp (Vec2D a, Vec2D b, float64 f)
type Vec2D
params a First input vector (maps to f=0).
  b Second input vector (maps to f=1).
  f The interpolation factor in the range [0..1].
returns The interpolated vector.

Linearly interpolates between the given vectors.

[Pure]
public static method Lerp (Vec3D a, Vec3D b, float64 f)
type Vec3D
params a First input vector (maps to f=0).
  b Second input vector (maps to f=1).
  f The interpolation factor in the range [0..1].
returns The interpolated vector.

PointOnLine

Computes the projection of a point to a line.

[Pure]
public static method PointOnLine (Vec3D p, Vec3D s, Vec3D v)
type float64
params p The point.
  s A point on the line.
  v Direction vector of the line.
returns The coefficient t for computing the projected point on the line:
p' = s + v * t

RLength

Computes the reciprocal length of the given vector.

[Pure]
public static method RLength (float64 x, float64 y)
type float64
params x X-component of vector.
  y Y-component of vector.
returns The reciprocal vector length or 0 if all vector components are zero.

Computes the reciprocal length of the given vector.

[Pure]
public static method RLength (float32 x, float32 y)
type float32
params x X-component of vector.
  y Y-component of vector.
returns The reciprocal vector length or 0 if all vector components are zero.

Computes the reciprocal length of the given vector.

[Pure]
public static method RLength (float64 x, float64 y, float64 z)
type float64
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The reciprocal vector length or 0 if all vector components are zero.

Computes the reciprocal length of the given vector.

[Pure]
public static method RLength (float32 x, float32 y, float32 z)
type float32
params x X-component of vector.
  y Y-component of vector.
  z Z-component of vector.
returns The reciprocal vector length or 0 if all vector components are zero.

Slerp

Spherically interpolates between the given vectors.

[Pure]
public static method Slerp (Vec2D a, Vec2D b, float64 f)
type Vec2D
params a First input vector (maps to f=0).
  b Second input vector (maps to f=1).
  f The interpolation factor in the range [0..1].
returns The interpolated vector.

Spherically interpolates between the given vectors.

[Pure]
public static method Slerp (Vec3D a, Vec3D b, float64 f)
type Vec3D
params a First input vector (maps to f=0).
  b Second input vector (maps to f=1).
  f The interpolation factor in the range [0..1].
returns The interpolated vector.

SortByX

Sorts the given 2D points by their coordinates (X ascending, Y ascending).

[Pure]
public static method SortByX (Vec2D a, Vec2D b)
type int32
params a First point.
  b Second point.
returns The comparison result.

SortByXY

Sorts the given 2D points by their coordinates (X ascending, Y ascending).

[Pure]
public static method SortByXY (Vec2D a, Vec2D b)
type int32
params a First point.
  b Second point.
returns The comparison result.

SphericalToCartesian

Converts the given spherical coordinates into cartesian coordinates.

[Pure]
public static method SphericalToCartesian (Vec3D spherical)
type Vec3D
params spherical The spherical coordinates.
returns The cartesian coordinates.

Remarks:

The components of the given vector have the following semantic:

spherical.X := radius (distance to origin).
spherical.Y := azimuthal angle (angle from positive X-axis in radians) in the range [-PI..PI].
spherical.Z := polar angle (angle from positive Z-axis in radians) in the range [0..PI].


Converts the given spherical coordinates into cartesian coordinates.

[Pure]
public static method SphericalToCartesian (float64 x, float64 y, float64 z)
type Vec3D
params x The spherical X-coordinate.
  y The spherical Y-coordinate.
  z The spherical Z-coordinate.
returns The cartesian coordinates.

Remarks:

The components of the given vector have the following semantic:

spherical.X := radius (distance to origin).
spherical.Y := azimuthal angle (angle from positive X-axis in radians) in the range [-PI..PI].
spherical.Z := polar angle (angle from positive Z-axis in radians) in the range [0..PI].

Volume

Computes the volume of the given tetrahedron.

[Pure]
public static method Volume (Vec3D a, Vec3D b, Vec3D c, Vec3D d)
type float64
params a First vertex of tetrahedron.
  b Second vertex of tetrahedron.
  c Third vertex of tetrahedron.
  d Fourth vertex of tetrahedron.
returns The volume of the tetrahedron.

Computes the volume of the given tetrahedron.

[Pure]
public static method Volume (float64 x1, float64 y1, float64 z1, float64 x2, float64 y2, float64 z2, float64 x3, float64 y3, float64 z3, float64 x4, float64 y4, float64 z4)
type float64
params x1 X-coordinate of first vertex of tetrahedron.
  y1 Y-coordinate of first vertex of tetrahedron.
  z1 Z-coordinate of first vertex of tetrahedron.
  x2 X-coordinate of second vertex of tetrahedron.
  y2 Y-coordinate of second vertex of tetrahedron.
  z2 Z-coordinate of second vertex of tetrahedron.
  x3 X-coordinate of third vertex of tetrahedron.
  y3 Y-coordinate of third vertex of tetrahedron.
  z3 Z-coordinate of third vertex of tetrahedron.
  x4 X-coordinate of fourth vertex of tetrahedron.
  y4 Y-coordinate of fourth vertex of tetrahedron.
  z4 Z-coordinate of fourth vertex of tetrahedron.
returns The volume of the tetrahedron.

Winding

Returns the winding at the joint of two connected line segments.

[Pure]
public static method Winding (Vec2D a, Vec2D b, Vec2D c)
type int32
params a Start of first line segment.
  b End of first line segment, start of second line segment.
  c End of second line segment.
returns [-1..1] The winding (see remarks).

Remarks:

The winding is defined as the sign of the Z-component of the cross product between b-a and c-b. The Z-components of a, b and c are assumed to be 0. A winding of zero means that all three points lie on the same line (i.e. the input vectors of the cross product are collinear). For a standard Cartesian coordinate system (X-axis points to the right, Y-axis points upwards), clockwise is negative and counter-clockwise is positive.


Returns the winding at the joint of two connected line segments.

[Pure]
public static method Winding (float64 ax, float64 ay, float64 bx, float64 by, float64 cx, float64 cy)
type int32
params ax X-coordinate of start of first line segment.
  ay Y-coordinate of start of first line segment.
  bx X-coordinate of end of first line segment, start of second line segment.
  by Y-coordinate of end of first line segment, start of second line segment.
  cx X-coordinate of end of second line segment.
  cy Y-coordinate of end of second line segment.
returns [-1..1] The winding (see remarks).

Remarks:

The winding is defined as the sign of the Z-component of the cross product between b-a and c-b. The Z-components of a, b and c are assumed to be 0. A winding of zero means that all three points lie on the same line (i.e. the input vectors of the cross product are collinear). For a standard Cartesian coordinate system (X-axis points to the right, Y-axis points upwards), clockwise is negative and counter-clockwise is positive.