vtdata library
Classes | Macros | Typedefs | Functions
MathTypes.h File Reference

Classes

class  FPoint3
 
class  DPoint3
 
class  FPoint2
 
class  DPoint2
 
class  IPoint2
 
class  DLine2
 
class  FLine2
 
class  DLine3
 
class  FLine3
 
class  FPlane
 
class  FBox3
 
class  FSphere
 
class  DPolygon2
 
class  DPolyArray
 
class  FPolygon3
 
class  DRECT
 
class  FRECT
 
class  DMatrix3
 
class  DMatrix4
 
class  FMatrix3
 
class  FMatrix4
 
class  FQuat
 
class  FPQ
 
class  RGBi
 
class  RGBAi
 
class  RGBf
 
class  RGBAf
 
class  ScopedLocale
 

Macros

#define PId   3.14159265358979323846264338
 
#define PIf   3.14159265358979323846264338f
 
#define PI2d   6.28318530717958647692528676
 
#define PI2f   6.28318530717958647692528676f
 
#define PID2d   1.57079632679489661923132169
 
#define PID2f   1.57079632679489661923132169f
 
#define PID3d   1.04719755119659774615421446
 
#define NULL   0
 

Typedefs

typedef std::vector< DLine2DLine2Array
 
typedef std::vector< FLine3FLine3Array
 
typedef float FMatrix4Data[4][4]
 

Functions

float random_offset (float x)
 
float random (float x)
 
int vt_log2 (int n)
 
float vt_log2f (float n)
 
double AngleSideVector (const DPoint2 &p0, const DPoint2 &p1, const DPoint2 &p2, DPoint2 &sideways)
 
float AngleSideVector (const FPoint3 &p0, const FPoint3 &p1, const FPoint3 &p2, FPoint3 &sideways)
 
bool CrossingsTest (const DPoint2 *pgon, int numverts, const DPoint2 &point)
 
bool CrossingsTest (const DPoint3 *pgon, int numverts, const DPoint2 &point)
 
bool PointInTriangle (const FPoint2 &p, const FPoint2 &p1, const FPoint2 &p2, const FPoint2 &p3)
 
bool PointInTriangle (const DPoint2 &p, const DPoint2 &p1, const DPoint2 &p2, const DPoint2 &p3)
 
bool BarycentricCoords (const FPoint2 &p1, const FPoint2 &p2, const FPoint2 &p3, const FPoint2 &p, float fBary[3])
 
bool BarycentricCoords (const DPoint2 &p1, const DPoint2 &p2, const DPoint2 &p3, const DPoint2 &p, double fBary[3])
 
bool PlaneIntersection (const FPlane &plane1, const FPlane &plane2, const FPlane &plane3, FPoint3 &result)
 
double DistancePointToLine (const DPoint2 &p1, const DPoint2 &p2, const DPoint2 &p3)
 
float DistanceLineToLine (const FPoint3 &A1, const FPoint3 &A2, const FPoint3 &B1, const FPoint3 &B2, FPoint3 &result1, FPoint3 &result2)
 
float DistanceSegmentToSegment (const FPoint3 &A1, const FPoint3 &A2, const FPoint3 &B1, const FPoint3 &B2, FPoint3 &result1, FPoint3 &result2)
 
int LineSegmentsIntersect (const DPoint2 &p1, const DPoint2 &p2, const DPoint2 &p3, const DPoint2 &p4, DPoint2 *result=NULL)
 
void vtLogMatrix (const FMatrix4 &mat)
 
void vtLogMatrix (const FMatrix3 &mat)
 
bool RaySphereIntersection (const FPoint3 &rkOrigin, const FPoint3 &rkDirection, const FSphere &rkSphere, int &riQuantity, FPoint3 akPoint[2])
 
void ProjectionXZ (const FLine3 &fline3, DLine2 &dline2)
 
void ProjectionXZ (const FPolygon3 &fpoly3, DPolygon2 &dpoly2)
 
void ProjectionXZ (const DLine2 &dline2, float fY, FLine3 &fline3)
 
void ProjectionXZ (const DPolygon2 &dpoly2, float fY, FPolygon3 &fpoly3)
 
double AreaOfTriangle (const DPoint2 &A, const DPoint2 &B, const DPoint2 &C)
 
double AreaOfTriangle (const DPoint3 &A, const DPoint3 &B, const DPoint3 &C)
 

Function Documentation

double AngleSideVector ( const DPoint2 p0,
const DPoint2 p1,
const DPoint2 p2,
DPoint2 sideways 
)

Given three points in a polyline, determine a side vector will will offset the polyline, to the left, by a unit width.

float AngleSideVector ( const FPoint3 p0,
const FPoint3 p1,
const FPoint3 p2,
FPoint3 sideways 
)

Given three points in a polyline, determine a side vector will will offset the polyline by a unit width.

bool BarycentricCoords ( const FPoint2 p1,
const FPoint2 p2,
const FPoint2 p3,
const FPoint2 p,
float  fBary[3] 
)

Compute the 3 barycentric coordinates of a 2D point in a 2D triangle.

Returns
false if a problem was encountered (e.g. degenerate triangle), otherwise true.
bool BarycentricCoords ( const DPoint2 p1,
const DPoint2 p2,
const DPoint2 p3,
const DPoint2 p,
double  fBary[3] 
)

Compute the 3 barycentric coordinates of a 2D point in a 2D triangle.

Returns
false if a problem was encountered (e.g. degenerate triangle), otherwise true.
bool CrossingsTest ( const DPoint2 pgon,
int  numverts,
const DPoint2 point 
)

Point-in-polygon test.

Tests whether the 2D polygon pgon with numverts number of vertices contains the test point point.

Returns
1 if inside, 0 if outside.
bool CrossingsTest ( const DPoint3 pgon,
int  numverts,
const DPoint2 point 
)

Another version of CrossingsTest that accepts 3D rather than 2D points. Only the first two components (X and Y) are tested, so this allows you to do a 2D test with a 3D polygon.

float DistanceLineToLine ( const FPoint3 A1,
const FPoint3 A2,
const FPoint3 B1,
const FPoint3 B2,
FPoint3 result1,
FPoint3 result2 
)

Given the four vectors defining your points A1, A2, B1, and B2, the points result1 and result2 on the lines A1A2 and B1B2, respectively, which are closest together, and their distance, d, apart.

double DistancePointToLine ( const DPoint2 p1,
const DPoint2 p2,
const DPoint2 p3 
)

Find the closest distance from a point to a line segment.

Parameters
p1,p2The points which define the line segment.
p3The point to which to measure distance.
int LineSegmentsIntersect ( const DPoint2 p1,
const DPoint2 p2,
const DPoint2 p3,
const DPoint2 p4,
DPoint2 result 
)

Test whether two 2D line segment intersect or not. Based on the algorithm 'Faster Line Segment Intersection' by Franklin Antonio

Returns
0 if the segments do not intersect, 1 if they do, 2 if the segments are parallel.
bool PlaneIntersection ( const FPlane plane1,
const FPlane plane2,
const FPlane plane3,
FPoint3 result 
)

Find the intersection of 3 planes.

Returns
true if there was a valid intersection point. The function will fail and return false for any degenerate case, e.g. when any two of the planes are parallel.
bool PointInTriangle ( const FPoint2 p,
const FPoint2 p1,
const FPoint2 p2,
const FPoint2 p3 
)

2D point in triangle containment test.

Returns
true if the point is inside the triangle, otherwise false.
bool PointInTriangle ( const DPoint2 p,
const DPoint2 p1,
const DPoint2 p2,
const DPoint2 p3 
)

2D point in triangle containment test.

Returns
true if the point is inside the triangle, otherwise false.
void ProjectionXZ ( const FLine3 fline3,
DLine2 dline2 
)

To convert between 3D and 2D entities, project to and from the 3D coordinate system's XZ plane.

int vt_log2 ( int  n)

Compute base-2 logarithm of an integer. There's probably an even simpler way to do this with sneaky logical ops or without a loop, but this works.