Go to the documentation of this file.
69 #pragma warning(disable:4786)
79 const double DEG_TO_RAD = ((2.0f * 3.14152654f) / 360.0f);
80 const double RAD_TO_DEG = (360.0f / (2.0f * 3.141592654f));
117 return( a.
x ==
x && a.
y ==
y && a.
z ==
z );
122 return( a.
x !=
x || a.
y !=
y || a.
z !=
z );
158 {
x/=A;
y/=A;
z/=A; };
161 {
x+=A.
x;
y+=A.
y;
z+=A.
z; };
163 {
x-=A.
x;
y-=A.
y;
z-=A.
z; };
168 {
x+=A;
y+=A;
z+=A; };
176 {
return( (i==0)?
x:((i==1)?
y:
z) ); };
178 {
return( (i==0)?
x:((i==1)?
y:
z) ); };
182 Type
GetX(
void)
const {
return x; };
183 Type
GetY(
void)
const {
return y; };
184 Type
GetZ(
void)
const {
return z; };
186 Type
X(
void)
const {
return x; };
187 Type
Y(
void)
const {
return y; };
188 Type
Z(
void)
const {
return z; };
196 double dx = fabsf(
x - v.
x );
197 if ( dx > epsilon )
return false;
198 double dy = fabsf(
y - v.
y );
199 if ( dy > epsilon )
return false;
200 double dz = fabsf(
z - v.
z );
201 if ( dz > epsilon )
return false;
210 double vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag;
220 vw_x = vy * wz - vz * wy;
221 vw_y = vz * wx - vx * wz;
222 vw_z = vx * wy - vy * wx;
224 mag = sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
226 if ( mag < 0.000001f )
245 x = (
x*c0) + (pos.
x*c1);
246 y = (
y*c0) + (pos.
y*c1);
247 z = (
z*c0) + (pos.
z*c1);
279 void Set(Type a,Type b,Type c)
291 const Type*
Ptr()
const {
return &
x; }
307 return Type(sqrt(
x *
x +
y *
y +
z *
z));
312 return Type(sqrt(
x *
x +
y *
y +
z *
z));
317 return Type(sqrt(
x *
x +
y *
y +
z *
z));
337 double d = sqrtf(
x*
x +
y*
y +
z*
z );
338 double recip = 1.0f / d;
350 const int *source = (
const int *) &
x;
351 const int *dest = (
const int *) &p.
x;
353 if ( source[0] == dest[0] &&
354 source[1] == dest[1] &&
355 source[2] == dest[2] )
return true;
362 if (
x == p.
x &&
y == p.
y &&
z == p.
z )
return true;
373 double dot = a.
Dot(b) * 2.0f;
393 return Type(sqrt(
x*
x +
y*
y +
z*
z ));
401 double vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag;
411 vw_x = vy * wz - vz * wy;
412 vw_y = vz * wx - vx * wz;
413 vw_z = vx * wy - vy * wx;
415 mag = sqrt((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
417 if ( mag < 0.000001f )
431 double D = 0.0f - ((
x*A.
x)+(
y*A.
y)+(
z*A.
z));
439 return Type(sqrt(
x*
x +
y*
y +
z*
z ));
445 return Type(sqrt(
x*
x +
y*
y +
z*
z ));
477 double dist = dx*dx + dy*dy;
486 return dx*dx + dy*dy + dz*dz;
491 return (
x*p.
y) - (p.
x*
y);
504 double d = sqrtf(
static_cast< double >(
x*
x +
y*
y +
z*
z ) );
521 double d = sqrt(
static_cast< double >(
x*
x +
y*
y +
z*
z ) );
538 double d = sqrt(
static_cast< double >(
x*
x +
y*
y +
z*
z ) );
558 return (
x * a.x +
y * a.y +
z * a.z );
571 x = a.
y*b.
z - a.
z*b.
y;
572 y = a.
z*b.
x - a.
x*b.
z;
573 z = a.
x*b.
y - a.
y*b.
x;
584 double vx,vy,vz,wx,wy,wz,vw_x,vw_y,vw_z,mag,nx,ny,nz,mag_a,mag_b;
590 mag_a = (double) sqrtf((wx * wx) + (wy * wy) + (wz * wz));
596 mag_b = (double) sqrtf((vx * vx) + (vy * vy) + (vz * vz));
598 vw_x = (vy * wz) - (vz * wy);
599 vw_y = (vz * wx) - (vx * wz);
600 vw_z = (vx * wy) - (vy * wx);
602 mag = (double) sqrtf((vw_x * vw_x) + (vw_y * vw_y) + (vw_z * vw_z));
612 if (mag/(mag_a*mag_b) <= 0.0f )
return true;
625 mag = (
x * nx) + (
y * ny) + (
z * nz);
627 if (mag > 0.0f )
return false;
634 if (((( i.
y <=
y ) && (
y < j.
y )) ||
635 (( j.
y <=
y ) && (
y < i.
y ))) &&
636 (
x < (j.
x - i.
x) * (
y - i.
y) / (j.
y - i.
y) + i.
x))
return true;
646 double ax = p3.
x - p2.
x;
647 double ay = p3.
y - p2.
y;
648 double bx = p1.
x - p3.
x;
649 double by = p1.
y - p3.
y;
650 double cx = p2.
x - p1.
x;
651 double cy = p2.
y - p1.
y;
652 double apx =
x - p1.
x;
653 double apy =
y - p1.
y;
654 double bpx =
x - p2.
x;
655 double bpy =
y - p2.
y;
656 double cpx =
x - p3.
x;
657 double cpy =
y - p3.
y;
659 double aCROSSbp = ax*bpy - ay*bpx;
660 double cCROSSap = cx*apy - cy*apx;
661 double bCROSScp = bx*cpy - by*cpx;
663 return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
672 double ay = p3.
y - p2.
y;
673 double az = p3.
z - p2.
z;
674 double by = p1.
y - p3.
y;
675 double bz = p1.
z - p3.
z;
676 double cy = p2.
y - p1.
y;
677 double cz = p2.
z - p1.
z;
678 double apy =
y - p1.
y;
679 double apz =
z - p1.
z;
680 double bpy =
y - p2.
y;
681 double bpz =
z - p2.
z;
682 double cpy =
y - p3.
y;
683 double cpz =
z - p3.
z;
685 double aCROSSbp = ay*bpz - az*bpy;
686 double cCROSSap = cy*apz - cz*apy;
687 double bCROSScp = by*cpz - bz*cpy;
689 return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
699 double az = p3.
z - p2.
z;
700 double ax = p3.
x - p2.
x;
701 double bz = p1.
z - p3.
z;
702 double bx = p1.
x - p3.
x;
703 double cz = p2.
z - p1.
z;
704 double cx = p2.
x - p1.
x;
705 double apz =
z - p1.
z;
706 double apx =
x - p1.
x;
707 double bpz =
z - p2.
z;
708 double bpx =
x - p2.
x;
709 double cpz =
z - p3.
z;
710 double cpx =
x - p3.
x;
712 double aCROSSbp = az*bpx - ax*bpz;
713 double cCROSSap = cz*apx - cx*apz;
714 double bCROSScp = bz*cpx - bx*cpz;
716 return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
731 nearestPoint = line0;
735 double delta = (
point-line0).
Dot(lineDelta) / (lineDelta).
Dot(lineDelta);
736 nearestPoint = line0 + delta*lineDelta;
752 nearestPoint = line0;
756 double delta = (
point-line0).
Dot(lineDelta) / (lineDelta).
Dot(lineDelta);
761 else if ( delta > 1 )
764 nearestPoint = line0 + delta*lineDelta;
782 normal.
Cross(lineDelta0, lineDelta1);
784 double delta = normal.
Dot(pointDelta) / normal.
Dot(normal);
785 nearestPoint =
point - delta*normal;
797 double delta = planeNormal.
Dot(pointDelta) / planeNormal.
Dot(planeNormal);
798 nearestPoint =
point - delta*planeNormal;
816 if ( (lineDelta0 == zeroVector) || (lineDelta1 == zeroVector) )
820 else if ( lineDelta0 == lineDelta1 )
833 axisDot[0] = (triangle0-axis[0]).
Dot(
point-axis[0]);
834 axisDot[1] = (triangle1-axis[1]).
Dot(
point-axis[1]);
835 axisDot[2] = (triangle2-axis[2]).
Dot(
point-axis[2]);
838 Type bestMagnitude2 = 0;
839 Type closeMagnitude2;
842 if ( axisDot[0] < 0 )
845 closeMagnitude2 =
point.Distance2(closePoint);
846 if ( bForce || (bestMagnitude2 > closeMagnitude2) )
849 bestMagnitude2 = closeMagnitude2;
850 nearestPoint = closePoint;
853 if ( axisDot[1] < 0 )
856 closeMagnitude2 =
point.Distance2(closePoint);
857 if ( bForce || (bestMagnitude2 > closeMagnitude2) )
860 bestMagnitude2 = closeMagnitude2;
861 nearestPoint = closePoint;
864 if ( axisDot[2] < 0 )
867 closeMagnitude2 =
point.Distance2(closePoint);
868 if ( bForce || (bestMagnitude2 > closeMagnitude2) )
871 bestMagnitude2 = closeMagnitude2;
872 nearestPoint = closePoint;
883 normal.
Cross(lineDelta0, lineDelta1);
886 double delta = normal.
Dot(pointDelta) / normal.
Dot(normal);
888 nearestPoint =
point - delta*normal;
926 const Type*
Ptr()
const {
return &
x; }
959 if ( a.
x ==
x && a.
y ==
y )
return true;
965 if ( a.
x !=
x || a.
y !=
y )
return true;
1015 return (
x * a.x +
y * a.y );
1046 return (Type) sqrtf(
x *
x +
y *
y );
1051 return (Type) sqrt(
x *
x +
y *
y );
1056 return (Type) sqrt(
x *
x +
y *
y );
1063 return Type(sqrtf(
x*
x +
y*
y ));
1068 return Type(sqrt(
x*
x +
y*
y ));
1073 return Type(sqrt(
x*
x +
y*
y ));
1085 Type d = dx*dx+dy*dy;
1093 Type d = dx*dx+dy*dy;
1101 Type d = dx*dx+dy*dy;
1109 return dx*dx + dy *dy;
1121 x = a.
y*b.
x - a.
x*b.
y;
1122 y = a.
x*b.
x - a.
x*b.
x;
Vector3d(const Vector3d &a)
Type Distance2(Vector2d &a)
void ScaleSumScale(double c0, double c1, const Vector3d< double > &pos)
Type Partial(const Vector3d< Type > &p) const
Type Distance(const Vector3d< Type > &a) const
Vector3d(Type a, Type b, Type c)
bool BinaryEqual(const Vector3d< double > &p) const
Type FasterNormalize(void)
Vector3d negative(void) const
Type FastLength(void) const
void Set(Type a, Type b, Type c)
Type fastmagnitude(void) const
bool operator==(const Vector2d< Type > &a) const
void NearestPointInPlane(const Vector3d< Type > &point, const Vector3d< Type > &planePoint, const Vector3d< Type > &planeNormal)
void operator-=(const Vector3d A)
Line(const Vector3d< double > &from, const Vector3d< double > &to)
Type DistanceXY(const Vector3d< Type > &a) const
Type FastMagnitude(void) const
double ComputeNormal(const Vector3d< double > &A, const Vector3d< double > &B, const Vector3d< double > &C)
Vector3d & operator=(const Vector3d &A)
Vector2d & operator*=(const Vector2d &a)
Vector2d(const Vector2d &a)
Type fastermagnitude(void) const
Type operator[](const int i) const
bool operator!=(const Vector3d< Type > &a) const
std::vector< Vector2d< double > > Vector2dVector
Type FastLength(void) const
void Cross(const Vector3d< Type > &a, const Vector3d< Type > &b)
void Lerp(const Vector2d< Type > &from, const Vector2d< Type > &to, double slerp)
double dot(const double3 &a, const double3 &b)
Vector2d operator+(Vector2d a) const
void Lerp(const Vector3d< Type > &from, const Vector3d< Type > &to, double slerp)
bool PointTestXY(const Vector3d< double > &i, const Vector3d< double > &j) const
Vector3d< Type > Cross(const Vector3d< Type > &other) const
Vector3d operator+(const Vector3d &A) const
bool Concave(const Vector3d< double > &a, const Vector3d< double > &b)
double FastNormalize(void)
Type Magnitude(void) const
bool PointInTriXY(const Vector3d< double > &p1, const Vector3d< double > &p2, const Vector3d< double > &p3) const
void NearestPointInTriangle(const Vector3d< Type > &point, const Vector3d< Type > &triangle0, const Vector3d< Type > &triangle1, const Vector3d< Type > &triangle2)
Type FasterLength(void) const
bool operator==(const Vector3d< Type > &a) const
Type Dot(const Vector3d< Type > &a) const
Vector2d & operator/=(const Vector2d &a)
bool IsSame(const Vector3d< double > &v, double epsilon) const
Vector2d negative(void) const
double ComputePlane(const Vector3d< double > &A, const Vector3d< double > &B, const Vector3d< double > &C)
void AngleAxis(Type angle, const Vector3d< Type > &axis)
bool PointInTriYZ(const Vector3d< double > &p1, const Vector3d< double > &p2, const Vector3d< double > &p3) const
void NearestPointInLine(const Vector3d< Type > &point, const Vector3d< Type > &line0, const Vector3d< Type > &line1)
Vector2d(const double *t)
Type FasterMagnitude(void) const
Vector2d operator*(Vector2d a) const
Vector3d(const double *t)
bool operator!=(const Vector2d &a) const
bool BinaryEqual(const Vector3d< int > &p) const
bool PointInTriXZ(const Vector3d< double > &p1, const Vector3d< double > &p2, const Vector3d< double > &p3) const
double FasterNormalize(void)
Quaternion slerp(Quaternion a, const Quaternion &b, double interp)
std::vector< Vector3d< double > > Vector3dVector
Type Distance2(const Vector3d< Type > &a) const
Vector3d operator*(const double s) const
Vector2d & operator+=(const Vector2d &a)
Type Distance(const Vector2d &a) const
Type Area(const Vector3d< Type > &p1, const Vector3d< Type > &p2) const
Vector2d & operator-=(const Vector2d &a)
void NearestPointInPlane(const Vector3d< Type > &point, const Vector3d< Type > &triangle0, const Vector3d< Type > &triangle1, const Vector3d< Type > &triangle2)
bool Intersect(const Line &src, Vector3d< double > §)
Vector2d operator/(Vector2d a) const
void Cross(const Vector2d< Type > &a, const Vector2d< Type > &b)
Type FasterDistance(const Vector3d< Type > &a) const
Type FasterDistance(const Vector2d &a) const
void Reflection(const Vector3d< Type > &a, const Vector3d< Type > &b)
void operator+=(const Vector3d A)
Vector2d operator-(void) const
Vector2d operator-(Vector2d a) const
Type FasterLength(void) const
Type Dot(const Vector2d< Type > &a) const
Type FastDistance(const Vector2d &a) const
void Interpolate(const Vector3d< double > &from, const Vector3d< double > &to, double offset)
void NearestPointInLineSegment(const Vector3d< Type > &point, const Vector3d< Type > &line0, const Vector3d< Type > &line1)
Vector2d operator*(Type c) const
Vector3d operator-(void) const
Type FastDistance(const Vector3d< Type > &a) const
void operator*=(const double s)
Vector3d operator/(const double s) const
double3 operator*(const double3 &v, const double s)
Type magnitude(void) const
void Reflection(Vector2d &a, Vector2d &b)
void Set(const double *p)