198 lines
3.5 KiB
C++
198 lines
3.5 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TGPlane3D.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 类的定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TGPlane3D.h"
|
|
#include "TGRegionEx2D.h"
|
|
#include "TPGeGLine3D.h"
|
|
#include "TGPoint3D.h"
|
|
#include "TPGeGLineRay3D.h"
|
|
#include "TGSolid.h"
|
|
#include "TPGeGLineSeg3D.h"
|
|
|
|
IMPLEMENT_RUN_TIME_CLASS1(TGPlane3D,"TGPlane3D",TPGeFace3D)
|
|
|
|
TGPlane3D::TGPlane3D()
|
|
{
|
|
|
|
}
|
|
|
|
TGPlane3D::TGPlane3D(const TGVector3D&vt,const TGPoint&pt)
|
|
: TPGePlane(vt,pt)
|
|
{
|
|
|
|
}
|
|
|
|
TGPlane3D::TGPlane3D(const TPGePlane&plane)
|
|
: TPGePlane(plane)
|
|
{
|
|
|
|
}
|
|
|
|
TGPlane3D::~TGPlane3D()
|
|
{
|
|
|
|
}
|
|
|
|
TGObject2D* TGPlane3D::Convert2D() const
|
|
{
|
|
return new TGRegionEx2D;
|
|
}
|
|
|
|
bool TGPlane3D::GetPlane(TPGePlane&plane) const
|
|
{
|
|
plane = *this;
|
|
return true;
|
|
}
|
|
|
|
bool TGPlane3D::IsValid() const
|
|
{
|
|
return !TPGePlane::IsNullVector();
|
|
}
|
|
|
|
TGObject * TGPlane3D::Clone() const
|
|
{
|
|
return new TGPlane3D(*this);
|
|
}
|
|
|
|
void TGPlane3D::TransformBy(const TGMatrix&matrix)
|
|
{
|
|
TPGePlane::TransformBy(&matrix);
|
|
}
|
|
|
|
GRelation TGPlane3D::HitTest(const TGPoint&pt) const
|
|
{
|
|
return TPGePlane::HitTest(pt);
|
|
}
|
|
|
|
bool TGPlane3D::Intersect(const TGObject&obj,TGObjectList&res) const
|
|
{
|
|
switch(obj.GetClassID())
|
|
{
|
|
case CID_GLine3D:
|
|
{
|
|
const TPGeGLine3D&line = (const TPGeGLine3D&)obj;
|
|
double pa;
|
|
int ret = TPGePlane::Intersect(line,pa);
|
|
if (ret == INT_1PT)
|
|
{
|
|
TGPoint3D *pPt = new TGPoint3D;
|
|
line.Pa2Pt(pa,*pPt);
|
|
res << pPt;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
res << obj.Clone();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
case CID_GLineRay3D:
|
|
{
|
|
const TPGeGLineRay3D&line = (const TPGeGLineRay3D&)obj;
|
|
double pa;
|
|
int ret = TPGePlane::Intersect(line,pa);
|
|
if (ret == INT_1PT && UPEQUAL_ZERO(pa))
|
|
{
|
|
TGPoint3D *pPt = new TGPoint3D;
|
|
line.Pa2Pt(pa,*pPt);
|
|
res << pPt;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
res << obj.Clone();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
case CID_GLineSeg3D:
|
|
{
|
|
const TPGeGLineSeg3D&line = (const TPGeGLineSeg3D&)obj;
|
|
double pa;
|
|
int ret = TPGePlane::Intersect(line,pa);
|
|
if (ret == INT_1PT && UPEQUAL_ZERO(pa) && DOWNEQUAL_ZERO(pa-1))
|
|
{
|
|
TGPoint3D *pPt = new TGPoint3D;
|
|
line.Pa2Pt(pa,*pPt);
|
|
res << pPt;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
res << obj.Clone();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
case CID_GPlane3D:
|
|
{
|
|
const TGPlane3D&plane = (const TGPlane3D&)obj;
|
|
TPGeGLine3D *pLine = new TPGeGLine3D;
|
|
int ret = TPGePlane::Intersect(plane,*pLine);
|
|
if (ret == INT_LINE)
|
|
{
|
|
res<<pLine;
|
|
}
|
|
else
|
|
{
|
|
delete pLine;
|
|
if (ret == INT_PLANE)
|
|
{
|
|
res<<Clone();
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return obj.Intersect(*this,res);
|
|
}
|
|
|
|
bool TGPlane3D::IsInclude(const TGObject&obj) const
|
|
{
|
|
if (IS_TYPE(&obj,TGPoint3D))
|
|
{
|
|
return HitTest((const TGPoint3D&)obj).Is(GR_IN);
|
|
}
|
|
if (IS_CLASS(&obj,TPGeGLine3D))
|
|
{
|
|
const TPGeGLine3D&line = (const TPGeGLine3D&)obj;
|
|
return HitTest(line.basePoint).Is(GR_IN) && IsVert(line);
|
|
}
|
|
|
|
if (IS_CLASS(&obj,TGSolid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const TGObject3D&obj3d = (const TGObject3D&)obj;
|
|
TPGePlane plane;
|
|
if (obj3d.GetPlane(plane))
|
|
{
|
|
return IsSamePlane(plane,false);
|
|
}
|
|
|
|
if (IS_CLASS(&obj,TPGeFace3D))
|
|
{
|
|
return false;
|
|
}
|
|
return TGObject::IsInclude(obj);
|
|
} |