20 #ifndef __OpenKarto_Geometry_h__ 21 #define __OpenKarto_Geometry_h__ 194 inline Size3(T width, T height, T depth)
399 if (rOther.
m_Values[0] > m_Values[0])
404 if (rOther.
m_Values[1] > m_Values[1])
425 return sqrt(SquaredLength());
435 return (*
this - rOther).SquaredLength();
445 return sqrt(SquaredDistance(rOther));
501 m_Values[0] /= scalar;
502 m_Values[1] /= scalar;
510 return Vector2(m_Values[0] / scalar, m_Values[1] / scalar);
526 return Vector2(m_Values[0] * scalar, m_Values[1] * scalar);
534 return Vector2(m_Values[0] - scalar, m_Values[1] - scalar);
542 m_Values[0] *= scalar;
543 m_Values[1] *= scalar;
551 return (m_Values[0] == rOther.
m_Values[0] && m_Values[1] == rOther.
m_Values[1]);
559 return (m_Values[0] != rOther.
m_Values[0] || m_Values[1] != rOther.
m_Values[1]);
570 if (m_Values[0] < rOther.
m_Values[0])
574 else if (m_Values[0] > rOther.
m_Values[0])
580 return (m_Values[1] < rOther.
m_Values[1]);
652 m_Values[0] = rVector.
GetX();
653 m_Values[1] = rVector.
GetY();
768 return sqrt(SquaredLength());
781 m_Values[0] *= inversedLength;
782 m_Values[1] *= inversedLength;
783 m_Values[2] *= inversedLength;
828 return Vector3(m_Values[0] + scalar, m_Values[1] + scalar, m_Values[2] + scalar);
844 return Vector3(m_Values[0] - scalar, m_Values[1] - scalar, m_Values[2] - scalar);
852 return Vector3(m_Values[0] * scalar, m_Values[1] * scalar, m_Values[2] * scalar);
914 m_Values[0] += rValue;
915 m_Values[1] += rValue;
916 m_Values[2] += rValue;
928 m_Values[0] -= rValue;
929 m_Values[1] -= rValue;
930 m_Values[2] -= rValue;
940 m_Values[0] *= rValue;
941 m_Values[1] *= rValue;
942 m_Values[2] *= rValue;
954 m_Values[0] /= rValue;
955 m_Values[1] /= rValue;
956 m_Values[2] /= rValue;
982 if (m_Values[0] < rOther.
m_Values[0])
986 else if (m_Values[0] > rOther.
m_Values[0])
990 else if (m_Values[1] < rOther.
m_Values[1])
994 else if (m_Values[1] > rOther.
m_Values[1])
1000 return (m_Values[2] < rOther.
m_Values[2]);
1009 return (m_Values[0] == rOther.
m_Values[0] && m_Values[1] == rOther.
m_Values[1] && m_Values[2] == rOther.
m_Values[2]);
1017 return (m_Values[0] != rOther.
m_Values[0] || m_Values[1] != rOther.
m_Values[1] || m_Values[2] != rOther.
m_Values[2]);
1055 template<
typename T>
1208 if (m_Values[0] < rOther.
m_Values[0])
1212 else if (m_Values[0] > rOther.
m_Values[0])
1216 else if (m_Values[1] < rOther.
m_Values[1])
1220 else if (m_Values[1] > rOther.
m_Values[1])
1224 else if (m_Values[2] < rOther.
m_Values[2])
1228 else if (m_Values[2] > rOther.
m_Values[2])
1234 return (m_Values[3] < rOther.
m_Values[3]);
1341 m_Values[0] = rVector.
GetX();
1342 m_Values[1] = rVector.
GetY();
1343 m_Values[2] = rVector.
GetZ();
1344 m_Values[3] = rVector.
GetW();
1437 return Vector4d(m_Values[0], m_Values[1], m_Values[2], m_Values[3]);
1476 return sqrt(Norm());
1485 return m_Values[0]*m_Values[0] + m_Values[1]*m_Values[1] + m_Values[2]*m_Values[2] + m_Values[3]*m_Values[3];
1496 kt_double inversedLength = 1.0 / length;
1498 m_Values[0] *= inversedLength;
1499 m_Values[1] *= inversedLength;
1500 m_Values[2] *= inversedLength;
1501 m_Values[3] *= inversedLength;
1564 uv = qvec ^ rVector;
1567 uv *= ( 2.0 * m_Values[3] );
1570 return rVector + uv + uuv;
1606 BoundingBox2(
const Vector2d& rMinimum,
const Vector2d& rMaximum);
1624 m_Minimum = rMinimum;
1642 m_Maximum = rMaximum;
1651 Vector2d size = m_Maximum - m_Minimum;
1660 inline void Add(
const Vector2d& rPoint)
1662 m_Minimum.MakeFloor(rPoint);
1663 m_Maximum.MakeCeil(rPoint);
1763 m_Minimum = rMinimum;
1781 m_Maximum = rMaximum;
1797 template<
typename T>
1817 , m_Size(width, height)
1827 : m_Position(rPosition)
1838 : m_Position(rTopLeft)
1839 , m_Size(rBottomRight.GetX() - rTopLeft.GetX(), rBottomRight.GetY() - rTopLeft.GetY())
1847 : m_Position(rOther.m_Position)
1848 , m_Size(rOther.m_Size)
1859 return m_Position.GetX();
1868 m_Position.SetX(rX);
1877 return m_Position.GetY();
1886 m_Position.SetY(rY);
1895 return m_Size.GetWidth();
1904 m_Size.SetWidth(rWidth);
1913 return m_Size.GetHeight();
1922 m_Size.SetHeight(rHeight);
1950 m_Position = rPosition;
1977 return m_Position.GetX();
1986 m_Position.SetX(rLeft);
1995 return m_Position.GetY();
2004 m_Position.SetY(rTop);
2013 return m_Position.GetX() + m_Size.GetWidth();
2022 m_Size.SetWidth(rRight - m_Position.GetX());
2031 return m_Position.GetY() + m_Size.GetHeight();
2040 m_Size.SetHeight(rBottom - m_Position.GetY());
2085 return Vector2<T>(m_Position.GetX() + m_Size.GetWidth() * 0.5, m_Position.GetY() + m_Size.GetHeight() * 0.5);
2095 T l1 = m_Position.GetX();
2096 T r1 = m_Position.GetX();
2097 if (m_Size.GetWidth() < 0)
2098 l1 += m_Size.GetWidth();
2100 r1 += m_Size.GetWidth();
2106 if (rOther.
m_Size.GetWidth() < 0)
2107 l2 += rOther.
m_Size.GetWidth();
2109 r2 += rOther.
m_Size.GetWidth();
2113 if (l2 < l1 || r2 > r1)
2116 T t1 = m_Position.GetY();
2117 T b1 = m_Position.GetY();
2118 if (m_Size.GetHeight() < 0)
2119 t1 += m_Size.GetHeight();
2121 b1 += m_Size.GetHeight();
2127 if (rOther.
m_Size.GetHeight() < 0)
2128 t2 += rOther.
m_Size.GetHeight();
2130 b2 += rOther.
m_Size.GetHeight();
2134 if (t2 < t1 || b2 > b1)
2222 return m_Position.GetX();
2240 return m_Position.GetY();
2267 m_Position = rPosition;
2285 m_Heading = heading;
2295 return m_Position.SquaredDistance(rOther.
m_Position);
2424 : m_Position(rPosition)
2434 : m_Position(rPosition)
2435 , m_Orientation(rOrientation)
2443 : m_Position(rOther.m_Position)
2444 , m_Orientation(rOther.m_Orientation)
2455 m_Orientation.FromEulerAngles(rPose.
GetHeading(), 0.0, 0.0);
2474 m_Position = rPosition;
2483 return m_Orientation;
2492 m_Orientation = rOrientation;
2582 memset(m_Matrix, 0, 9*
sizeof(
kt_double));
2586 m_Matrix[i][i] = 1.0;
2595 memset(m_Matrix, 0, 9*
sizeof(
kt_double));
2609 kt_double oneMinusCos = 1.0 - cosRadians;
2623 m_Matrix[0][0] = xx * oneMinusCos + cosRadians;
2624 m_Matrix[0][1] = xyMCos - zSin;
2625 m_Matrix[0][2] = xzMCos + ySin;
2627 m_Matrix[1][0] = xyMCos + zSin;
2628 m_Matrix[1][1] = yy * oneMinusCos + cosRadians;
2629 m_Matrix[1][2] = yzMCos - xSin;
2631 m_Matrix[2][0] = xzMCos - ySin;
2632 m_Matrix[2][1] = yzMCos + xSin;
2633 m_Matrix[2][2] = zz * oneMinusCos + cosRadians;
2648 transpose.
m_Matrix[row][col] = m_Matrix[col][row];
2662 kt_bool haveInverse = InverseFast(kInverse, 1e-14);
2663 if (haveInverse ==
false)
2678 for (
int row = 0; row < 3; row++)
2680 for (
int col = 0; col < 3; col++)
2708 return m_Matrix[row][column];
2719 return m_Matrix[row][column];
2729 for (
size_t row = 0; row < 3; row++)
2731 for (
size_t col = 0; col < 3; col++)
2733 product.
m_Matrix[row][col] = m_Matrix[row][0]*rOther.
m_Matrix[0][col] + m_Matrix[row][1]*rOther.
m_Matrix[1][col] + m_Matrix[row][2]*rOther.
m_Matrix[2][col];
2747 pose2.
SetX(m_Matrix[0][0] * rPose2.
GetX() + m_Matrix[0][1] * rPose2.
GetY() + m_Matrix[0][2] * rPose2.
GetHeading());
2748 pose2.
SetY(m_Matrix[1][0] * rPose2.
GetX() + m_Matrix[1][1] * rPose2.
GetY() + m_Matrix[1][2] * rPose2.
GetHeading());
2763 m_Matrix[row][col] += rkMatrix.
m_Matrix[row][col];
2809 rkInverse.
m_Matrix[0][0] = m_Matrix[1][1]*m_Matrix[2][2] - m_Matrix[1][2]*m_Matrix[2][1];
2810 rkInverse.
m_Matrix[0][1] = m_Matrix[0][2]*m_Matrix[2][1] - m_Matrix[0][1]*m_Matrix[2][2];
2811 rkInverse.
m_Matrix[0][2] = m_Matrix[0][1]*m_Matrix[1][2] - m_Matrix[0][2]*m_Matrix[1][1];
2812 rkInverse.
m_Matrix[1][0] = m_Matrix[1][2]*m_Matrix[2][0] - m_Matrix[1][0]*m_Matrix[2][2];
2813 rkInverse.
m_Matrix[1][1] = m_Matrix[0][0]*m_Matrix[2][2] - m_Matrix[0][2]*m_Matrix[2][0];
2814 rkInverse.
m_Matrix[1][2] = m_Matrix[0][2]*m_Matrix[1][0] - m_Matrix[0][0]*m_Matrix[1][2];
2815 rkInverse.
m_Matrix[2][0] = m_Matrix[1][0]*m_Matrix[2][1] - m_Matrix[1][1]*m_Matrix[2][0];
2816 rkInverse.
m_Matrix[2][1] = m_Matrix[0][1]*m_Matrix[2][0] - m_Matrix[0][0]*m_Matrix[2][1];
2817 rkInverse.
m_Matrix[2][2] = m_Matrix[0][0]*m_Matrix[1][1] - m_Matrix[0][1]*m_Matrix[1][0];
2821 if (fabs(fDet) <= fTolerance)
2827 for (
size_t row = 0; row < 3; row++)
2829 for (
size_t col = 0; col < 3; col++)
2831 rkInverse.
m_Matrix[row][col] *= fInvDet;
2864 : m_Red(rOther.m_Red)
2865 , m_Green(rOther.m_Green)
2866 , m_Blue(rOther.m_Blue)
2867 , m_Alpha(rOther.m_Alpha)
3123 kt_double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong);
3144 SetX(GetLongitude() + longitude);
3145 SetY(GetLatitude() - latitude);
3168 const kt_double t2 = clat1 * slat2 - slat1 * clat2 * cdlon;
3169 const kt_double t3 = slat1 * slat2 + clat1 * clat2 * cdlon;
3170 const kt_double dist = atan2(sqrt(t1*t1 + t2*t2), t3);
3173 return dist * earthRadius;
3227 template<
typename T>
3233 template<
typename T>
3239 template<
typename T>
3245 template<
typename T>
3251 template<
typename T>
3262 stringValue = tempString.
SubString(0, index);
3269 tempString = rStringValue.
SubString(index + 1, rStringValue.
Size());
3272 stringValue = tempString.
SubString(0, index);
3279 tempString = rStringValue.
SubString(index + 1, rStringValue.
Size());
3282 stringValue = tempString.
SubString(index + 1, rStringValue.
Size());
3302 #endif // __OpenKarto_Geometry_h__ void Add(const BoundingBox2 &rBoundingBox)
kt_bool InverseFast(Matrix3 &rkInverse, kt_double fTolerance=KT_TOLERANCE) const
void Append(const String &rString)
PointGps(const PointGps &rOther)
const Vector2 operator-(const Vector2 &rOther) const
Vector4(const Vector4 &rOther)
void AddOffset(kt_double latitude, kt_double longitude)
const Vector2 operator*(T scalar) const
kt_double Distance(const Vector2 &rOther) const
Vector3 & operator=(const Vector3 &rOther)
Matrix3(const Matrix3 &rOther)
void SetSize(const Size2< T > &rSize)
Vector3 & operator/=(const T &rValue)
karto::Vector3d operator*(const karto::Vector3d &rVector) const
kt_double SquaredLength() const
const Vector3 operator^(const Vector3 &rOther) const
kt_double GetHeading() const
void MakeCeil(const Vector2 &rOther)
const String ToString() const
kt_double & operator()(kt_int32u row, kt_int32u column)
void SetWidth(const T &rWidth)
Vector2< T > GetTopRight()
Vector3(const Vector2< T > &rVector)
Pose2 operator-(const Pose2 &rOther) const
const Vector3d & GetPosition() const
void SetPosition(const T &rX, const T &rY)
kt_size_t FindFirstOf(const String &rValue) const
void SetMaximum(const Vector2d &rMaximum)
Rectangle2(const Vector2< T > &rTopLeft, const Vector2< T > &rBottomRight)
Vector3 & operator-=(const Vector3 &rOther)
Vector2< T > GetAsVector2() const
const String ToString() const
List< PointGps > PointGpsList
void operator*=(T scalar)
void SetTop(const T &rTop)
Vector3< kt_int32u > Vector3iu
String SubString(kt_size_t index) const
Size2(const Size2 &rOther)
kt_bool operator!=(const Size3 &rOther) const
kt_bool operator==(const Vector4 &rOther) const
kt_double AngleTo(const Vector2d &rVector) const
kt_bool operator!=(const Pose2 &rOther) const
Vector3(const Vector3 &rOther)
Vector3 & operator-=(const T &rValue)
friend KARTO_FORCEINLINE std::ostream & operator<<(std::ostream &rStream, const Size2 &rSize)
kt_bool operator!=(const Vector2 &rOther) const
void operator+=(const Vector2 &rOther)
const Vector3 operator+(const Vector3 &rOther) const
kt_bool operator!=(const Size2 &rOther) const
Matrix3 Transpose() const
const Vector3d & GetMinimum() const
void SetMinimum(const Vector3d &rMinimum)
TFSIMD_FORCE_INLINE const tfScalar & y() const
kt_bool operator!=(const Vector3 &rOther) const
Vector3 & operator+=(const T &rValue)
Rectangle2(const Rectangle2 &rOther)
const Vector2< T > GetCenter() const
kt_double Distance(const PointGps &rOther)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
void SetPosition(const Vector2< T > &rPosition)
Size3(T width, T height, T depth)
void SetLeft(const T &rLeft)
kt_double operator*(const Vector2 &rOther) const
kt_bool Contains(const Rectangle2< T > &rOther)
const String ToString() const
Vector2< kt_int32u > Vector2iu
Pose3(const Pose3 &rOther)
Size3(const Size3 &rOther)
kt_bool operator==(const Pose2 &rOther) const
#define KARTO_FORCEINLINE
const kt_double GetRed() const
Vector2< T > GetBottomRight()
Vector4(T x, T y, T z, T w)
kt_bool operator==(const Vector2 &rOther) const
friend KARTO_FORCEINLINE std::ostream & operator<<(std::ostream &rStream, const Quaternion &rQuaternion)
kt_double SquaredDistance(const Pose2 &rOther) const
Quaternion(kt_double x, kt_double y, kt_double z, kt_double w)
kt_double GetBearing(const PointGps &rOther)
const kt_double GetGreen() const
void SetPosition(const Vector2d &rPosition)
Vector2< T > GetTopLeft()
kt_bool operator!=(const Vector4 &rOther) const
kt_bool operator<(const Vector3 &rOther) const
Quaternion(const Quaternion &rOther)
Size2< kt_double > GetSize() const
Vector3 & operator*=(const Vector3 &rOther)
void SetBlue(kt_double blue)
void SetGreen(kt_double green)
void SetRight(const T &rRight)
void operator+=(const Pose2 &rOther)
Color(kt_double red, kt_double green, kt_double blue, kt_double alpha=1.0)
void SetPosition(const Vector3d &rPosition)
const String ToString() const
const kt_double GetAlpha() const
void MakeFloor(const Vector2 &rOther)
void operator/=(T scalar)
Vector3 & operator/=(const Vector3 &rOther)
const Vector2 operator/(T scalar) const
static String ToString(const char *value)
const kt_double KT_TOLERANCE
Pose3(const Vector3d &rPosition)
kt_double GetLatitude() const
kt_bool operator==(const Size3 &rOther) const
Pose2 operator+(const Pose2 &rOther) const
Vector4< kt_double > Vector4d
Vector3< kt_int32s > Vector3i
TFSIMD_FORCE_INLINE const tfScalar & x() const
const String ToString() const
Rectangle2(const Vector2< T > &rPosition, const Size2< T > &rSize)
kt_bool operator<(const Vector2 &rOther) const
friend KARTO_FORCEINLINE std::ostream & operator<<(std::ostream &rStream, const Vector4 &rVector)
void SetLatitude(kt_double latitude)
const Vector2d & GetMinimum() const
const Vector3 operator-(kt_double scalar) const
kt_double SquaredDistance(const Vector2 &rOther) const
const Quaternion operator*(const Quaternion &rOther) const
const karto::String ToString() const
kt_bool operator==(const Quaternion &rOther) const
Vector3< kt_double > Vector3d
const String ToString() const
void operator-=(const Vector2 &rOther)
void SetMaximum(const Vector3d &rMaximum)
const Vector2d & GetPosition() const
const Vector2< T > & GetPosition() const
kt_bool Contains(const BoundingBox2 &rOther) const
const Vector2 operator-(T scalar) const
static kt_bool FromString(const String &rStringValue, Vector3< T > &rValue)
const Vector4d GetAsVector4() const
void SetHeight(const T &rHeight)
kt_bool operator==(const Vector3 &rOther) const
const Vector2 operator+(const Vector2 &rOther) const
kt_double operator()(kt_int32u row, kt_int32u column) const
Pose3(const Vector3d &rPosition, const karto::Quaternion &rOrientation)
Color(kt_int8u red, kt_int8u green, kt_int8u blue, kt_int8u alpha=255)
Vector3 & operator+=(const Vector3 &rOther)
Quaternion & operator=(const Quaternion &rOther)
void SetBottom(const T &rBottom)
void operator+=(const Matrix3 &rkMatrix)
const Vector3d & GetMaximum() const
Vector2< kt_double > Vector2d
kt_bool operator<(const Vector4 &rOther) const
kt_bool operator!=(const Quaternion &rOther) const
Quaternion(const Vector4d &rVector)
kt_double DegreesToRadians(kt_double degrees)
kt_double NormalizeAngle(kt_double angle)
kt_bool InRange(const T &value, const T &a, const T &b)
const Vector3 operator-(const Vector3 &rOther) const
kt_bool Contains(const Vector2d &rPoint) const
kt_bool operator==(const Size2 &rOther) const
Rectangle2(T x, T y, T width, T height)
void SetAlpha(kt_double alpha)
void MakeFloor(const Vector3 &rOther)
kt_bool DoubleEqual(kt_double a, kt_double b)
kt_double SquaredLength() const
const karto::String ToString() const
kt_double GetLongitude() const
const String ToString(kt_int32u precision=4) const
const Quaternion & GetOrientation() const
const Vector3 operator*(T scalar) const
Pose3(const Pose2 &rPose)
void SetHeading(kt_double heading)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
friend KARTO_FORCEINLINE std::ostream & operator<<(std::ostream &rStream, const Vector2 &rVector)
Vector2< T > GetBottomLeft()
const char * ToCString() const
Matrix3 operator*(const Matrix3 &rOther) const
void SetLongitude(kt_double longitude)
const Vector2d & GetMaximum() const
void SetOrientation(const Quaternion &rOrientation)
void SetRed(kt_double red)
Vector2< kt_int32s > Vector2i
Size2 & operator=(const Size2 &rOther)
kt_bool Intersects(const BoundingBox2 &rOther) const
const Vector3 operator+(kt_double scalar) const
Color(const Color &rOther)
const T GetHeight() const
const String ToString() const
const kt_double GetBlue() const
void SetMinimum(const Vector2d &rMinimum)
const String ToString() const
void AddOffset(const PointGps &rOffset)
Vector4< kt_int32s > Vector4i
void Add(const Vector2d &rPoint)
kt_bool operator==(const Matrix3 &rkMatrix)
Size3 & operator=(const Size3 &rOther)
Pose2 operator*(const Pose2 &rPose2) const
Vector4< kt_int32u > Vector4iu
kt_double RadiansToDegrees(kt_double radians)
PointGps(kt_double latitude, kt_double longitude)
const Size2< T > & GetSize() const
void FromAxisAngle(kt_double x, kt_double y, kt_double z, const kt_double radians)
void MakeCeil(const Vector3 &rOther)
Vector3 & operator*=(const T &rValue)