214 lines
4.2 KiB
C++
214 lines
4.2 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeCoordSys 类
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TPGeCoordSys 定义
|
|
// = Maintainers:
|
|
//
|
|
//-------------------------------------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeCoordSys.h"
|
|
#include "TGMatrix.h"
|
|
|
|
TPGeCoordSys TPGeCoordSys::WCS;
|
|
|
|
TPGeCoordSys::TPGeCoordSys()
|
|
{
|
|
Reset();
|
|
}
|
|
|
|
TPGeCoordSys::TPGeCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& y,const TGVector3D& z)
|
|
{
|
|
Set(pt,x,y,z);
|
|
}
|
|
|
|
TPGeCoordSys::TPGeCoordSys(const TGPoint& pt,const TGVector3D& z,bool bRight)
|
|
{
|
|
Set(pt,z,bRight);
|
|
}
|
|
|
|
TPGeCoordSys::TPGeCoordSys(const TPGePlane& plane,bool bRight)
|
|
{
|
|
Set(plane,bRight);
|
|
}
|
|
|
|
TPGeCoordSys::TPGeCoordSys(const TGPoint& pt,const TGVector3D& x,const TGVector3D& vt,bool bRight)
|
|
{
|
|
Set(pt,x,vt,bRight);
|
|
}
|
|
|
|
TPGeCoordSys::TPGeCoordSys(const TGPoint& pt,const TGPoint& xPt,const TGPoint& yPt,bool bRight)
|
|
{
|
|
Set(pt,xPt,yPt,bRight);
|
|
}
|
|
|
|
TPGeCoordSys::~TPGeCoordSys()
|
|
{
|
|
|
|
}
|
|
|
|
void TPGeCoordSys::Normalize()
|
|
{
|
|
xAxis.Normalize();
|
|
yAxis.Normalize();
|
|
zAxis.Normalize();
|
|
}
|
|
|
|
void TPGeCoordSys::Set(const TPGePlane& plane,bool bRight)
|
|
{
|
|
Set(plane.GetSamplePoint(),plane,bRight);
|
|
}
|
|
|
|
void TPGeCoordSys::Set(const TGPoint& pt,const TGVector3D& z,bool bRight)
|
|
{
|
|
TGVector3D x;
|
|
z.GetVertVector(x);
|
|
TGVector3D y = bRight ? z * x : x * z;
|
|
Set(pt,x,y,z);
|
|
}
|
|
|
|
void TPGeCoordSys::Set(const TGPoint& pt,const TGPoint& xPt,const TGPoint& yPt,bool bRight)
|
|
{
|
|
TGVector3D x(pt,xPt);
|
|
TGVector3D z = bRight ? x * TGVector3D(pt,yPt) : TGVector3D(pt,yPt) * x;
|
|
TGVector3D y = bRight ? z * x : x * z;
|
|
Set(pt,x,y,z);
|
|
}
|
|
|
|
void TPGeCoordSys::Set(const TGPoint& pt,const TGVector3D& x,const TGVector3D& vt,bool bRight)
|
|
{
|
|
TGVector3D z = bRight ? x * vt : vt * x;
|
|
TGVector3D y = bRight ? z * x : x * z;
|
|
Set(pt,x,y,z);
|
|
}
|
|
|
|
void TPGeCoordSys::GetMatrixTo(TGMatrix* pMat) const
|
|
{
|
|
TGMatrix mat;
|
|
mat[0][0] = xAxis.x;
|
|
mat[0][1] = xAxis.y;
|
|
mat[0][2] = xAxis.z;
|
|
mat[0][3] = 0;
|
|
|
|
mat[1][0] = yAxis.x;
|
|
mat[1][1] = yAxis.y;
|
|
mat[1][2] = yAxis.z;
|
|
mat[1][3] = 0;
|
|
|
|
mat[2][0] = zAxis.x;
|
|
mat[2][1] = zAxis.y;
|
|
mat[2][2] = zAxis.z;
|
|
mat[2][3] = 0;
|
|
|
|
mat[3][0] = origin.x;
|
|
mat[3][1] = origin.y;
|
|
mat[3][2] = origin.z;
|
|
mat[3][3] = 1;
|
|
|
|
pMat = &mat;
|
|
}
|
|
|
|
void TPGeCoordSys::GetMatrixFrom(TGMatrix* pMat) const
|
|
{
|
|
ASSERT(pMat != NULL);
|
|
|
|
GetMatrixTo(pMat);
|
|
pMat->Reverse();
|
|
}
|
|
|
|
void TPGeCoordSys::GetWcs(TPGeCoordSys& sys) const
|
|
{
|
|
TGMatrix m;
|
|
GetMatrixFrom(&m);
|
|
m.GetCoordSys(sys);
|
|
}
|
|
|
|
//轴矢量为单位矢量,且轴矢量不平行
|
|
bool TPGeCoordSys::IsValid() const
|
|
{
|
|
return xAxis.IsNormalized() && yAxis.IsNormalized() && zAxis.IsNormalized() &&
|
|
!xAxis.IsParallel(yAxis) && !xAxis.IsParallel(zAxis) && !yAxis.IsParallel(zAxis);
|
|
}
|
|
|
|
//设为世界坐标系
|
|
void TPGeCoordSys::Reset()
|
|
{
|
|
origin.SetPoint(0,0,0);
|
|
xAxis.SetVector(1,0,0);
|
|
yAxis.SetVector(0,1,0);
|
|
zAxis.SetVector(0,0,1);
|
|
}
|
|
|
|
void TPGeCoordSys::Set(const TGPoint& pt,const TGVector3D& x,const TGVector3D& y,const TGVector3D& z)
|
|
{
|
|
origin = pt;
|
|
xAxis = x;
|
|
yAxis = y;
|
|
zAxis = z;
|
|
Normalize();
|
|
}
|
|
|
|
void TPGeCoordSys::TransformBy(const TGMatrix* pMat)
|
|
{
|
|
ASSERT(pMat != NULL);
|
|
|
|
pMat->Transform3D(origin);
|
|
pMat->Transform(xAxis);
|
|
pMat->Transform(yAxis);
|
|
pMat->Transform(zAxis);
|
|
|
|
Normalize();
|
|
}
|
|
|
|
//从this向世界坐标变换
|
|
void TPGeCoordSys::TransWcs(TGPoint& pt) const
|
|
{
|
|
TGMatrix mat;
|
|
GetMatrixFrom(&mat);
|
|
mat.Transform3D(pt);
|
|
}
|
|
|
|
//从this向世界坐标变换
|
|
void TPGeCoordSys::TransWcs(TGVector3D& vt) const
|
|
{
|
|
TGMatrix mat;
|
|
GetMatrixFrom(&mat);
|
|
mat.Transform(vt);
|
|
}
|
|
|
|
//从世界坐标系向this变换
|
|
void TPGeCoordSys::TransUcs(TGPoint& pt) const
|
|
{
|
|
TGMatrix mat;
|
|
GetMatrixTo(&mat);
|
|
mat.Transform3D(pt);
|
|
}
|
|
|
|
//从世界坐标系向this变换
|
|
void TPGeCoordSys::TransUcs(TGVector3D& vt) const
|
|
{
|
|
TGMatrix mat;
|
|
GetMatrixTo(&mat);
|
|
mat.Transform(vt);
|
|
}
|
|
|
|
void TPGeCoordSys::GetXYPlane(TPGePlane& plane) const
|
|
{
|
|
plane.SetNormal(zAxis);
|
|
plane.SetBasePoint(origin);
|
|
}
|
|
|
|
void TPGeCoordSys::GetYZPlane(TPGePlane& plane) const
|
|
{
|
|
plane.SetNormal(xAxis);
|
|
plane.SetBasePoint(origin);
|
|
}
|
|
|
|
void TPGeCoordSys::GetZXPlane(TPGePlane& plane) const
|
|
{
|
|
plane.SetNormal(yAxis);
|
|
plane.SetBasePoint(origin);
|
|
}
|