Integrate Werners & Jans double branch

Move from float to double
Further suggestions for float -> double move
Moved Tools2D from float to double
More suggestions for float->double move from Gui subdirectory
Changes to FEM constraint visuals for float->double move
Suggested changes for float -> double move
Suggestions for Part module moving float -> double
This commit is contained in:
jriegel
2013-09-22 21:55:11 +02:00
parent 78ba09a490
commit 00ea24e07e
64 changed files with 719 additions and 589 deletions

View File

@@ -457,6 +457,133 @@ bool Matrix4D::toAxisAngle (Vector3f& rclBase, Vector3f& rclDir, float& rfAngle,
return true;
}
bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle, double& fTranslation) const
{
// First check if the 3x3 submatrix is orthogonal
for ( int i=0; i<3; i++ ) {
// length must be one
if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][i]+dMtrx4D[1][i]*dMtrx4D[1][i]+dMtrx4D[2][i]*dMtrx4D[2][i]-1.0) > 0.01 )
return false;
// scalar product with other rows must be zero
if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][(i+1)%3]+dMtrx4D[1][i]*dMtrx4D[1][(i+1)%3]+dMtrx4D[2][i]*dMtrx4D[2][(i+1)%3]) > 0.01 )
return false;
}
// Okay, the 3x3 matrix is orthogonal.
// Note: The section to get the rotation axis and angle was taken from WildMagic Library.
//
// Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
// The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where
// I is the identity and
//
// +- -+
// P = | 0 -z +y |
// | +z 0 -x |
// | -y +x 0 |
// +- -+
//
// If A > 0, R represents a counterclockwise rotation about the axis in
// the sense of looking from the tip of the axis vector towards the
// origin. Some algebra will show that
//
// cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P
//
// In the event that A = pi, R-R^t = 0 which prevents us from extracting
// the axis through P. Instead note that R = I+2*P^2 when A = pi, so
// P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
// z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
// it does not matter which sign you choose on the square roots.
//
// For more details see also http://www.math.niu.edu/~rusin/known-math/97/rotations
double fTrace = dMtrx4D[0][0] + dMtrx4D[1][1] + dMtrx4D[2][2];
double fCos = 0.5*(fTrace-1.0);
rfAngle = acos(fCos); // in [0,PI]
if ( rfAngle > 0.0f )
{
if ( rfAngle < F_PI )
{
rclDir.x = (dMtrx4D[2][1]-dMtrx4D[1][2]);
rclDir.y = (dMtrx4D[0][2]-dMtrx4D[2][0]);
rclDir.z = (dMtrx4D[1][0]-dMtrx4D[0][1]);
rclDir.Normalize();
}
else
{
// angle is PI
double fHalfInverse;
if ( dMtrx4D[0][0] >= dMtrx4D[1][1] )
{
// r00 >= r11
if ( dMtrx4D[0][0] >= dMtrx4D[2][2] )
{
// r00 is maximum diagonal term
rclDir.x = (0.5*sqrt(dMtrx4D[0][0] - dMtrx4D[1][1] - dMtrx4D[2][2] + 1.0));
fHalfInverse = 0.5/rclDir.x;
rclDir.y = (fHalfInverse*dMtrx4D[0][1]);
rclDir.z = (fHalfInverse*dMtrx4D[0][2]);
}
else
{
// r22 is maximum diagonal term
rclDir.z = (0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0));
fHalfInverse = 0.5/rclDir.z;
rclDir.x = (fHalfInverse*dMtrx4D[0][2]);
rclDir.y = (fHalfInverse*dMtrx4D[1][2]);
}
}
else
{
// r11 > r00
if ( dMtrx4D[1][1] >= dMtrx4D[2][2] )
{
// r11 is maximum diagonal term
rclDir.y = (0.5*sqrt(dMtrx4D[1][1] - dMtrx4D[0][0] - dMtrx4D[2][2] + 1.0));
fHalfInverse = 0.5/rclDir.y;
rclDir.x = (fHalfInverse*dMtrx4D[0][1]);
rclDir.z = (fHalfInverse*dMtrx4D[1][2]);
}
else
{
// r22 is maximum diagonal term
rclDir.z = (0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0));
fHalfInverse = 0.5/rclDir.z;
rclDir.x = (fHalfInverse*dMtrx4D[0][2]);
rclDir.y = (fHalfInverse*dMtrx4D[1][2]);
}
}
}
}
else
{
// The angle is 0 and the matrix is the identity. Any axis will
// work, so just use the x-axis.
rclDir.x = 1.0;
rclDir.y = 0.0;
rclDir.z = 0.0;
rclBase.x = 0.0;
rclBase.y = 0.0;
rclBase.z = 0.0;
}
// This is the translation part in axis direction
fTranslation = (dMtrx4D[0][3]*rclDir.x+dMtrx4D[1][3]*rclDir.y+dMtrx4D[2][3]*rclDir.z);
Vector3d cPnt(dMtrx4D[0][3],dMtrx4D[1][3],dMtrx4D[2][3]);
cPnt = cPnt - fTranslation * rclDir;
// This is the base point of the rotation axis
if ( rfAngle > 0.0f )
{
double factor = 0.5*(1.0+fTrace)/sin(rfAngle);
rclBase.x = (0.5*(cPnt.x+factor*(rclDir.y*cPnt.z-rclDir.z*cPnt.y)));
rclBase.y = (0.5*(cPnt.y+factor*(rclDir.z*cPnt.x-rclDir.x*cPnt.z)));
rclBase.z = (0.5*(cPnt.z+factor*(rclDir.x*cPnt.y-rclDir.y*cPnt.x)));
}
return true;
}
void Matrix4D::transform (const Vector3f& rclVct, const Matrix4D& rclMtrx)
{
move(-rclVct);

View File

@@ -110,12 +110,16 @@ public:
/// moves the coordinatesystem for the x,y,z value
void move (float x, float y, float z)
{ move(Vector3f(x,y,z)); }
void move (double x, double y, double z)
{ move(Vector3d(x,y,z)); }
/// moves the coordinatesystem for the vector
void move (const Vector3f& rclVct);
void move (const Vector3d& rclVct);
/// scale for the vector
void scale (float x, float y, float z)
{ scale(Vector3f(x,y,z)); }
void scale (double x, double y, double z)
{ scale(Vector3d(x,y,z)); }
/// scale for the x,y,z value
void scale (const Vector3f& rclVct);
void scale (const Vector3d& rclVct);
@@ -133,6 +137,7 @@ public:
void rotLine (const Vector3d& rclBase, const Vector3d& rclDir, double fAngle);
/// Extract the rotation axis and angle. Therefore the 3x3 submatrix must be orthogonal.
bool toAxisAngle (Vector3f& rclBase, Vector3f& rclDir, float& fAngle, float& fTranslation) const;
bool toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& fAngle, double& fTranslation) const;
/// transform (move,scale,rotate) around a point
void transform (const Vector3f& rclVct, const Matrix4D& rclMtrx);
void transform (const Vector3d& rclVct, const Matrix4D& rclMtrx);

View File

@@ -75,9 +75,9 @@ public:
* // read my Element
* reader.readElement("PropertyVector");
* // get the value of my Attribute
* _cVec.x = (float)reader.getAttributeAsFloat("valueX");
* _cVec.y = (float)reader.getAttributeAsFloat("valueY");
* _cVec.z = (float)reader.getAttributeAsFloat("valueZ");
* _cVec.x = reader.getAttributeAsFloat("valueX");
* _cVec.y = reader.getAttributeAsFloat("valueY");
* _cVec.z = reader.getAttributeAsFloat("valueZ");
* }
* \endcode
*/

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#ifndef _PreComp_
# include <cstdlib>
# include <set>
#endif
@@ -33,22 +33,22 @@
using namespace Base;
float Vector2D::GetAngle (const Vector2D &rclVect) const
double Vector2D::GetAngle (const Vector2D &rclVect) const
{
float fDivid, fNum;
double fDivid, fNum;
fDivid = Length() * rclVect.Length();
if ((fDivid < -1e-10f) || (fDivid > 1e-10f))
if ((fDivid < -1e-10) || (fDivid > 1e-10))
{
fNum = (*this * rclVect) / fDivid;
if (fNum < -1)
return F_PI;
else
if (fNum > 1)
return 0.0F;
return 0.0;
else
return float(acos(fNum));
return acos(fNum);
}
else
return -FLOAT_MAX; // division by zero
@@ -56,8 +56,8 @@ float Vector2D::GetAngle (const Vector2D &rclVect) const
void Vector2D::ProjToLine (const Vector2D &rclPt, const Vector2D &rclLine)
{
float l = rclLine.Length();
float t1 = (rclPt * rclLine) / l;
double l = rclLine.Length();
double t1 = (rclPt * rclLine) / l;
Vector2D clNormal = rclLine;
clNormal.Normalize();
clNormal.Scale(t1);
@@ -178,16 +178,16 @@ bool BoundBox2D::Contains (const Vector2D &rclV) const
BoundBox2D Line2D::CalcBoundBox (void) const
{
BoundBox2D clBB;
clBB.fMinX = std::min<float> (clV1.fX, clV2.fX);
clBB.fMinY = std::min<float> (clV1.fY, clV2.fY);
clBB.fMaxX = std::max<float> (clV1.fX, clV2.fX);
clBB.fMaxY = std::max<float> (clV1.fY, clV2.fY);
clBB.fMinX = std::min<double> (clV1.fX, clV2.fX);
clBB.fMinY = std::min<double> (clV1.fY, clV2.fY);
clBB.fMaxX = std::max<double> (clV1.fX, clV2.fX);
clBB.fMaxY = std::max<double> (clV1.fY, clV2.fY);
return clBB;
}
bool Line2D::Intersect (const Line2D& rclLine, Vector2D &rclV) const
{
float m1, m2, b1, b2;
double m1, m2, b1, b2;
// calc coefficients
if (fabs (clV2.fX - clV1.fX) > 1e-10)
@@ -225,7 +225,7 @@ bool Line2D::Intersect (const Line2D& rclLine, Vector2D &rclV) const
return true; /*** RETURN TRUE (intersection) **********/
}
Vector2D Line2D::FromPos (float fDistance) const
Vector2D Line2D::FromPos (double fDistance) const
{
Vector2D clDir(clV2 - clV1);
clDir.Normalize();
@@ -249,18 +249,18 @@ BoundBox2D Polygon2D::CalcBoundBox (void) const
BoundBox2D clBB;
for (i = 0; i < _aclVct.size(); i++)
{
clBB.fMinX = std::min<float> (clBB.fMinX, _aclVct[i].fX);
clBB.fMinY = std::min<float> (clBB.fMinY, _aclVct[i].fY);
clBB.fMaxX = std::max<float> (clBB.fMaxX, _aclVct[i].fX);
clBB.fMaxY = std::max<float> (clBB.fMaxY, _aclVct[i].fY);
clBB.fMinX = std::min<double> (clBB.fMinX, _aclVct[i].fX);
clBB.fMinY = std::min<double> (clBB.fMinY, _aclVct[i].fY);
clBB.fMaxX = std::max<double> (clBB.fMaxX, _aclVct[i].fX);
clBB.fMaxY = std::max<double> (clBB.fMaxY, _aclVct[i].fY);
}
return clBB;
}
static short _CalcTorsion (float *pfLine, float fX, float fY)
static short _CalcTorsion (double *pfLine, double fX, double fY)
{
short sQuad[2], i;
float fResX;
double fResX;
// Klassifizierung der beiden Polygonpunkte in Quadranten
for (i = 0; i < 2; i++)
@@ -297,7 +297,7 @@ bool Polygon2D::Contains (const Vector2D &rclV) const
// Ermittelt mit dem Verfahren der Windungszahl, ob ein Punkt innerhalb
// eines Polygonzugs enthalten ist.
// Summe aller Windungszahlen gibt an, ob ja oder nein.
float pfTmp[4];
double pfTmp[4];
unsigned long i;
short sTorsion = 0;
@@ -358,7 +358,7 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
Line2D clLine(clPt0, clPt1);
// try to intersect with each line of the trim-polygon
std::set<float> afIntersections; // set of intersections (sorted by line parameter)
std::set<double> afIntersections; // set of intersections (sorted by line parameter)
Vector2D clTrimPt2; // second line point
for (size_t i = 0; i < ulTrimCt; i++)
{
@@ -369,14 +369,14 @@ void Polygon2D::Intersect (const Polygon2D &rclPolygon, std::list<Polygon2D> &rc
if (clLine.IntersectAndContain(clToTrimLine, clV) == true)
{
// save line parameter of intersection point
float fDist = (clV - clPt0).Length();
double fDist = (clV - clPt0).Length();
afIntersections.insert(fDist);
}
}
if (afIntersections.size() > 0) // intersections founded
{
for (std::set<float>::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++)
for (std::set<double>::iterator pF = afIntersections.begin(); pF != afIntersections.end(); pF++)
{
// intersection point
Vector2D clPtIS = clLine.FromPos(*pF);

View File

@@ -45,7 +45,7 @@ class Polygon2D;
class BaseExport Vector2D
{
public:
float fX, fY;
double fX, fY;
inline Vector2D (void);
inline Vector2D (float x, float y);
@@ -53,19 +53,19 @@ public:
inline Vector2D (const Vector2D &rclVct);
// methods
inline float Length (void) const;
inline double Length (void) const;
// operators
inline Vector2D& operator= (const Vector2D &rclVct);
inline float operator* (const Vector2D &rclVct) const;
inline double operator* (const Vector2D &rclVct) const;
inline bool operator== (const Vector2D &rclVct) const;
inline Vector2D operator+ (const Vector2D &rclVct) const;
inline Vector2D operator- (const Vector2D &rclVct) const;
inline void Set (float fPX, float fPY);
inline void Scale (float fS);
inline void Set (double fPX, double fPY);
inline void Scale (double fS);
inline void Normalize (void);
float GetAngle (const Vector2D &rclVect) const;
double GetAngle (const Vector2D &rclVect) const;
void ProjToLine (const Vector2D &rclPt, const Vector2D &rclLine);
};
@@ -77,11 +77,11 @@ public:
class BaseExport BoundBox2D
{
public:
float fMinX, fMinY, fMaxX, fMaxY;
double fMinX, fMinY, fMaxX, fMaxY;
inline BoundBox2D (void);
inline BoundBox2D (const BoundBox2D &rclBB);
inline BoundBox2D (float fX1, float fY1, float fX2, float fY2);
inline BoundBox2D (double fX1, double fY1, double fX2, double fY2);
inline bool IsValid (void);
// operators
@@ -92,7 +92,7 @@ public:
bool operator|| (const Polygon2D &rclPoly) const;
inline void operator &= (const Vector2D &rclVct);
void SetVoid (void) { fMinX = fMinY = FLOAT_MAX; fMaxX = fMaxY = -FLOAT_MAX; }
void SetVoid (void) { fMinX = fMinY = DOUBLE_MAX; fMaxX = fMaxY = -DOUBLE_MAX; }
// misc
bool Contains (const Vector2D &rclV) const;
@@ -113,7 +113,7 @@ public:
inline Line2D (const Vector2D &rclV1, const Vector2D &rclV2);
// methods
inline float Length (void) const;
inline double Length (void) const;
BoundBox2D CalcBoundBox (void) const;
// operators
@@ -124,7 +124,7 @@ public:
inline bool Contains (const Vector2D &rclV) const;
bool Intersect (const Line2D& rclLine, Vector2D &rclV) const;
bool IntersectAndContain (const Line2D& rclLine, Vector2D &rclV) const;
Vector2D FromPos (float fDistance) const;
Vector2D FromPos (double fDistance) const;
};
/** Polygon2D ********************************************/
@@ -162,14 +162,14 @@ private:
inline void BoundBox2D::operator &= (const Vector2D &rclVct)
{
fMinX = std::min<float>(fMinX, rclVct.fX);
fMinY = std::min<float>(fMinY, rclVct.fY);
fMaxX = std::max<float>(fMaxX, rclVct.fX);
fMaxY = std::max<float>(fMaxY, rclVct.fY);
fMinX = std::min<double>(fMinX, rclVct.fX);
fMinY = std::min<double>(fMinY, rclVct.fY);
fMaxX = std::max<double>(fMaxX, rclVct.fX);
fMaxY = std::max<double>(fMaxY, rclVct.fY);
}
inline Vector2D::Vector2D (void)
: fX(0.0f), fY(0.0f)
: fX(0.0), fY(0.0)
{
}
@@ -179,8 +179,8 @@ inline Vector2D::Vector2D (float x, float y)
}
inline Vector2D::Vector2D (double x, double y)
: fX(float(x)),
fY(float(y))
: fX(x),
fY(y)
{
}
@@ -189,9 +189,9 @@ inline Vector2D::Vector2D (const Vector2D &rclVct)
{
}
inline float Vector2D::Length (void) const
inline double Vector2D::Length (void) const
{
return (float)sqrt ((fX * fX) + (fY * fY));
return sqrt ((fX * fX) + (fY * fY));
}
inline Vector2D& Vector2D::operator= (const Vector2D &rclVct)
@@ -216,12 +216,12 @@ inline Vector2D Vector2D::operator- (const Vector2D &rclVct) const
return Vector2D(fX - rclVct.fX, fY - rclVct.fY);
}
inline float Vector2D::operator* (const Vector2D &rclVct) const
inline double Vector2D::operator* (const Vector2D &rclVct) const
{
return (fX * rclVct.fX) + (fY * rclVct.fY);
}
inline void Vector2D::Scale (float fS)
inline void Vector2D::Scale (double fS)
{
fX *= fS;
fY *= fS;
@@ -229,7 +229,7 @@ inline void Vector2D::Scale (float fS)
inline void Vector2D::Normalize (void)
{
float fLen = Length();
double fLen = Length();
if (fLen != 0.0f)
{
fX /= fLen;
@@ -237,7 +237,7 @@ inline void Vector2D::Normalize (void)
}
}
inline void Vector2D::Set (float fPX, float fPY)
inline void Vector2D::Set (double fPX, double fPY)
{
fX = fPX;
fY = fPY;
@@ -304,7 +304,7 @@ inline Line2D::Line2D (const Vector2D &rclV1, const Vector2D &rclV2)
{
}
inline float Line2D::Length (void) const
inline double Line2D::Length (void) const
{
return (clV2 - clV1).Length ();
}
@@ -328,8 +328,8 @@ inline bool Line2D::Contains (const Vector2D &rclV) const
inline BoundBox2D::BoundBox2D (void)
{
fMinX = fMinY = FLOAT_MAX;
fMaxX = fMaxY = - FLOAT_MAX;
fMinX = fMinY = DOUBLE_MAX;
fMaxX = fMaxY = - DOUBLE_MAX;
}
inline BoundBox2D::BoundBox2D (const BoundBox2D &rclBB)
@@ -340,12 +340,12 @@ inline BoundBox2D::BoundBox2D (const BoundBox2D &rclBB)
{
}
inline BoundBox2D::BoundBox2D (float fX1, float fY1, float fX2, float fY2)
inline BoundBox2D::BoundBox2D (double fX1, double fY1, double fX2, double fY2)
{
fMinX = std::min<float>( fX1, fX2 );
fMaxX = std::max<float>( fX1, fX2 );
fMinY = std::min<float>( fY1, fY2 );
fMaxY = std::max<float>( fY1, fY2 );
fMinX = std::min<double>( fX1, fX2 );
fMaxX = std::max<double>( fX1, fX2 );
fMinY = std::min<double>( fY1, fY2 );
fMaxY = std::max<double>( fY1, fY2 );
}
inline bool BoundBox2D::IsValid (void)