|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include "dllExport.h"
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class XJ_ALGO_EXPORT Point3D //<2F><>ֵ<EFBFBD><D6B5><EFBFBD>ṹ<EFBFBD><E1B9B9>
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
double data[3]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
inline double& x() {return data[0];}
|
|
|
|
|
|
inline double& y() {return data[1];}
|
|
|
|
|
|
inline double& z() {return data[2];}
|
|
|
|
|
|
inline double x() const { return data[0]; }
|
|
|
|
|
|
inline double y() const { return data[1]; }
|
|
|
|
|
|
inline double z() const { return data[2]; }
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
|
|
|
|
|
|
Point3D() {data[0] = 0.0; data[1] = 0.0; data[2] = 0.0;}
|
|
|
|
|
|
Point3D(double x, double y, double z) {data[0] = x; data[1] = y; data[2] = z;}
|
|
|
|
|
|
Point3D(const Point3D& rhs) {data[0] = rhs.x(); data[1] = rhs.y(); data[2] = rhs.z();}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool IsZero() const { return (xjdef::equivalent(data[0], 0.0) && xjdef::equivalent(data[1], 0.0) && xjdef::equivalent(data[2], 0.0));}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------------ʸ<><CAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-----------------------------------*/
|
|
|
|
|
|
//<2F>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline Point3D operator + (const Point3D& rhs) const;
|
|
|
|
|
|
inline Point3D& operator += (const Point3D& rhs);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline Point3D operator - () const;
|
|
|
|
|
|
inline Point3D operator - ( const Point3D& rhs) const;
|
|
|
|
|
|
inline Point3D& operator -= (const Point3D& rhs);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline Point3D operator * (double rhs) const;
|
|
|
|
|
|
inline Point3D& operator *= (double rhs);
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline Point3D operator / (double rhs) const;
|
|
|
|
|
|
inline Point3D& operator /= (double rhs) ;
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline double operator * (const Point3D& rhs) const;
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void Cross(const Point3D& rhs);
|
|
|
|
|
|
Point3D Crossed(const Point3D& rhs) const;
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
void CrossCross(const Point3D& v1, const Point3D& v2);
|
|
|
|
|
|
|
|
|
|
|
|
//! Computes the double vector product this ^ (V1 ^ V2).
|
|
|
|
|
|
//! - CrossCrossed creates a new unit vector.
|
|
|
|
|
|
//! Exceptions
|
|
|
|
|
|
//! Standard_ConstructionError if:
|
|
|
|
|
|
//! - V1 and V2 are parallel, or
|
|
|
|
|
|
//! - this unit vector and (V1 ^ V2) are parallel.
|
|
|
|
|
|
//! This is because, in these conditions, the computed vector
|
|
|
|
|
|
//! is null and cannot be normalized.
|
|
|
|
|
|
Point3D CrossCrossed (const Point3D& V1, const Point3D& V2) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Get the perpendicular of this point to the line defined by rclBase and rclDir.
|
|
|
|
|
|
* Note: Do not mix up this method with ProjToLine.
|
|
|
|
|
|
*/
|
|
|
|
|
|
Point3D Perpedicular(const Point3D& rclBase, const Point3D& rclDir ) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==<3D><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline bool operator == (const Point3D& rhs) const {return data[0]==rhs.x() && data[1]==rhs.y() && data[2]==rhs.z();}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool operator != (const Point3D& rhs) const {return data[0]!=rhs.x() || data[1]!=rhs.y() || data[2]!=rhs.z();}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline Point3D& operator = (const Point3D& _v)
|
|
|
|
|
|
{
|
|
|
|
|
|
set(_v.x(), _v.y(), _v.z());
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void set(double x, double y, double z)
|
|
|
|
|
|
{
|
|
|
|
|
|
data[0] = x; data[1] = y; data[2] = z;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Magnitude
|
|
|
|
|
|
inline double Magnitude() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Normalize()
|
|
|
|
|
|
{
|
|
|
|
|
|
double length = sqrt(data[0] * data[0] + data[1] * data[1] + data[2] * data[2]);
|
|
|
|
|
|
if(length - 0.0 < 1e-12)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
data[0] = data[0] / length;
|
|
|
|
|
|
data[1] = data[1] / length;
|
|
|
|
|
|
data[2] = data[2] / length;
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
inline Point3D Normalize(const Point3D& dir) const
|
|
|
|
|
|
{
|
|
|
|
|
|
Point3D normalDir(dir.x(), dir.y(), dir.z());
|
|
|
|
|
|
normalDir.Normalize();
|
|
|
|
|
|
return normalDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
inline double Length() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return sqrt(data[0]*data[0] + data[1]*data[1] + data[2]*data[2]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline double Length2() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return data[0]*data[0] + data[1]*data[1] + data[2]*data[2];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline double dot(const Point3D& a_vector) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return((data[0] * a_vector.data[0]) + (data[1] * a_vector.data[1]) + (data[2] * a_vector.data[2]));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
|
inline const Point3D operator ^ (const Point3D& rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(data[1]*rhs.z() - data[2]*rhs.y(),
|
|
|
|
|
|
data[2]*rhs.x() - data[0]*rhs.z() ,
|
|
|
|
|
|
data[0]*rhs.y() - data[1]*rhs.x());
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D Point3D::operator + (const Point3D& rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(data[0] + rhs.x(), data[1] + rhs.y(), data[2] + rhs.z());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D& Point3D::operator += (const Point3D& rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
data[0] += rhs.x();
|
|
|
|
|
|
data[1] += rhs.y();
|
|
|
|
|
|
data[2] += rhs.z();
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D Point3D::operator - () const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(-data[0], -data[1], -data[2]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>const<73><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>const <20><><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>ʹ<EFBFBD><CAB9>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>벻ͨ<EBB2BB><CDA8>
|
|
|
|
|
|
inline Point3D Point3D::operator - (const Point3D& rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(data[0] - rhs.x(), data[1] - rhs.y(), data[2] - rhs.z());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D& Point3D::operator -= (const Point3D& rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
data[0] -= rhs.x();
|
|
|
|
|
|
data[1] -= rhs.y();
|
|
|
|
|
|
data[2] -= rhs.z();
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D Point3D::operator * (double rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(data[0] * rhs, data[1] * rhs, data[2] * rhs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D& Point3D::operator *= (double rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
data[0] *= rhs;
|
|
|
|
|
|
data[1] *= rhs;
|
|
|
|
|
|
data[2] *= rhs;
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D Point3D::operator/(double rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!xjdef::equivalent(rhs, 0.0))
|
|
|
|
|
|
return Point3D(data[0] / rhs, data[1] / rhs, data[2] / rhs);
|
|
|
|
|
|
|
|
|
|
|
|
return Point3D(0.0, 0.0, 0.0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline Point3D& Point3D::operator /= (double rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!xjdef::equivalent(rhs, 0.0))
|
|
|
|
|
|
{
|
|
|
|
|
|
data[0] /= rhs;
|
|
|
|
|
|
data[1] /= rhs;
|
|
|
|
|
|
data[2] /= rhs;
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
set(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline double Point3D::operator * (const Point3D& rhs) const
|
|
|
|
|
|
{
|
|
|
|
|
|
return data[0] * rhs.x() + data[1] * rhs.y() + data[2] * rhs.z();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//global function
|
|
|
|
|
|
inline Point3D operator * (double rhs, const Point3D& rvs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Point3D(rvs.x() * rhs, rvs.y() * rhs, rvs.z() * rhs);
|
|
|
|
|
|
}
|