250 lines
4.4 KiB
C++
250 lines
4.4 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeGLineRay3D.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: 类的定义
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeGLineRay3D.h"
|
|
#include "TPGeGLineSeg3D.h"
|
|
#include "TGPoint3D.h"
|
|
|
|
IMPLEMENT_RUN_TIME_CLASS1(TPGeGLineRay3D,"TPGeGLineRay3D",TPGeGLine3D)
|
|
|
|
TPGeGLineRay3D::TPGeGLineRay3D()
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay3D::TPGeGLineRay3D(const TGVector3D&vt,const TGPoint&pt)
|
|
: TPGeGLine3D(vt,pt)
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay3D::TPGeGLineRay3D(const TGPoint&pt0,const TGPoint&pt1)
|
|
: TPGeGLine3D(pt0,pt1)
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay3D::TPGeGLineRay3D(const TPGeLine3D&line)
|
|
: TPGeGLine3D(line)
|
|
{
|
|
|
|
}
|
|
|
|
TPGeGLineRay3D::~TPGeGLineRay3D()
|
|
{
|
|
|
|
}
|
|
|
|
bool TPGeGLineRay3D::IsFinite(bool bStart) const
|
|
{
|
|
return bStart ? true : false;
|
|
}
|
|
|
|
TGObject2D* TPGeGLineRay3D::Convert2D() const
|
|
{
|
|
return new TPGeGLineRay2D(TGVector2D(x,y),basePoint);
|
|
}
|
|
|
|
TGObject * TPGeGLineRay3D::Clone() const
|
|
{
|
|
return new TPGeGLineRay3D(*this);
|
|
}
|
|
|
|
GRelation TPGeGLineRay3D::HitTest(const TGPoint&pt) const
|
|
{
|
|
GRelation r = TPGeGLine3D::HitTest(pt);
|
|
if (r.Is(GR_IN))
|
|
{
|
|
double pa;
|
|
Pt2Pa(pt,pa);
|
|
if (DOWN_ZERO(pa))
|
|
{
|
|
return GR_OUT;
|
|
}
|
|
else
|
|
{
|
|
return GR_IN;
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
|
|
bool TPGeGLineRay3D::IsInclude(const TGObject&obj) const
|
|
{
|
|
switch(obj.GetClassID())
|
|
{
|
|
case CID_GLine3D:
|
|
return false;
|
|
case CID_GLineRay3D:
|
|
{
|
|
const TPGeGLineRay3D&ray = (const TPGeGLineRay3D&)obj;
|
|
if (GetGeLine() == ray.GetGeLine() && IsSameDirection(ray))
|
|
{
|
|
double pa;
|
|
Pt2Pa(ray.basePoint,pa);
|
|
return UPEQUAL_ZERO(pa);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
case CID_GLineSeg3D:
|
|
{
|
|
const TPGeGLineSeg3D&seg = (const TPGeGLineSeg3D&)obj;
|
|
if (GetGeLine() == seg.GetGeLine())
|
|
{
|
|
double pa;
|
|
Pt2Pa(seg.GetStartPoint(),pa);
|
|
if (DOWN_ZERO(pa))
|
|
{
|
|
return false;
|
|
}
|
|
Pt2Pa(seg.GetEndPoint(),pa);
|
|
return UPEQUAL_ZERO(pa);
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
default:
|
|
return TPGeCurve3D::IsInclude(obj);
|
|
}
|
|
}
|
|
|
|
bool TPGeGLineRay3D::Intersect(const TGObject&obj,TGObjectList&res) const
|
|
{
|
|
switch(obj.GetClassID())
|
|
{
|
|
case CID_GLine3D:
|
|
{
|
|
double pa;
|
|
int ret = TPGeLine3D::Intersect((const TPGeGLine3D&)obj,pa);
|
|
if (ret == INT_NULL)
|
|
{
|
|
return false;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
res<<new TPGeGLineRay3D(*this);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (DOWN_ZERO(pa))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
TGPoint3D *pPt = new TGPoint3D;
|
|
Pa2Pt(pa,*pPt);
|
|
res<<pPt;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
case CID_GLineRay3D:
|
|
{
|
|
double pa1,pa2;
|
|
const TPGeGLineRay3D&ray = (const TPGeGLineRay3D&)obj;
|
|
int ret = TPGeLine3D::Intersect(ray,pa1,pa2);
|
|
if (ret == INT_NULL)
|
|
{
|
|
return false;
|
|
}
|
|
else if (ret == INT_LINE)
|
|
{
|
|
Pt2Pa(ray.basePoint,pa1);
|
|
if (IsSameDirection(ray))
|
|
{
|
|
if (UP_ZERO(pa1))
|
|
{
|
|
res<<new TPGeGLineRay3D(ray);
|
|
}
|
|
else
|
|
{
|
|
res<<new TPGeGLineRay3D(*this);
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if (UP_ZERO(pa1))
|
|
{
|
|
res<<new TPGeGLineSeg3D(basePoint,ray.basePoint);
|
|
}
|
|
else if (DOWN_ZERO(pa1))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
res<<new TGPoint3D(basePoint);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (DOWN_ZERO(pa1) || DOWN_ZERO(pa2))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
TGPoint3D *pPt = new TGPoint3D;
|
|
Pa2Pt(pa1,*pPt);
|
|
res<<pPt;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
default:
|
|
return obj.Intersect(*this, res);
|
|
}
|
|
}
|
|
|
|
void TPGeGLineRay3D::Split(const TTable<double>&paTable,TGObjectList&res) const
|
|
{
|
|
if (paTable.IsEmpty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
TGPoint pt0;
|
|
if (UP_ZERO(paTable.GetAt(0)))
|
|
{
|
|
Pa2Pt(paTable.GetAt(0),pt0);
|
|
res<<new TPGeGLineSeg3D(basePoint,pt0);
|
|
}
|
|
else
|
|
{
|
|
pt0 = basePoint;
|
|
}
|
|
for (long i = 1;i<paTable.GetLength();i++)
|
|
{
|
|
if (UP_ZERO(paTable.GetAt(i)-paTable.GetAt(i-1)))
|
|
{
|
|
TGPoint pt1;
|
|
Pa2Pt(paTable.GetAt(i),pt1);
|
|
res<<new TPGeGLineSeg3D(pt0,pt1);
|
|
pt0 = pt1;
|
|
}
|
|
}
|
|
res<<new TPGeGLineRay3D(TGVector3D(*this),pt0);
|
|
}
|
|
|
|
bool TPGeGLineRay3D::IsSameRay(const TPGeGLineRay3D&ray) const
|
|
{
|
|
return basePoint == ray.basePoint && IsParallel(ray) && IsSameDirection(ray);
|
|
} |