111 lines
2.1 KiB
C++
111 lines
2.1 KiB
C++
#include "StdAfx.h"
|
||
#include "globalfunc.h"
|
||
#include "GeTriangle.h"
|
||
#include "GeLine.h"
|
||
#include "GeCurveInline.h"
|
||
|
||
void GeTriangle::Ecs2Wcs(TVector3D vtEcs)
|
||
{
|
||
vertex1 = GlobalFunc::Ecs2Wcs(vertex1, vtEcs);
|
||
vertex2 = GlobalFunc::Ecs2Wcs(vertex2, vtEcs);
|
||
vertex3 = GlobalFunc::Ecs2Wcs(vertex3, vtEcs);
|
||
}
|
||
|
||
void GeTriangle::Wcs2Ecs(TVector3D vtEcs)
|
||
{
|
||
vertex1 = GlobalFunc::Wcs2Ecs(vertex1, vtEcs);
|
||
vertex2 = GlobalFunc::Wcs2Ecs(vertex2, vtEcs);
|
||
vertex3 = GlobalFunc::Wcs2Ecs(vertex3, vtEcs);
|
||
}
|
||
|
||
// 判断三角形是否退化为线或点
|
||
int GeTriangle::IsLinear()
|
||
{
|
||
GeLine ln(vertex1, vertex2);
|
||
if (ln.GetLength() < 1E-9)
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
int nPrFlag = vertex3 & ln;
|
||
if (nPrFlag != PR_OUTSIDE)
|
||
{
|
||
return 1;
|
||
}
|
||
|
||
return 0;
|
||
}
|
||
|
||
// 1~3-命中1~3点;-1~-3 -命中1~3边;0-外部;4-内部
|
||
int GeTriangle::HitTest2d(const ADSGePoint3d &ptTest) const
|
||
{
|
||
// 0--错误;1-左边;2-右边;3-起始点;4-终止点;5-线内;6-起始侧延长线;7-终止侧延长线
|
||
int nHit1 = GeLine(vertex1, vertex2).HitTest2d(ptTest);
|
||
if (nHit1 == 3)
|
||
{
|
||
return HIT_VERTEX1; // verttex1
|
||
}
|
||
|
||
if (nHit1 == 4)
|
||
{
|
||
return HIT_VERTEX2;
|
||
}
|
||
|
||
if (nHit1 == 5)
|
||
{
|
||
return HIT_SIDE1;
|
||
}
|
||
|
||
int nHit2 = GeLine(vertex2, vertex3).HitTest2d(ptTest);
|
||
if (nHit2 == 4)
|
||
{
|
||
return HIT_VERTEX3;
|
||
}
|
||
|
||
if (nHit2 == 5)
|
||
{
|
||
return HIT_SIDE2;
|
||
}
|
||
|
||
int nHit3 = GeLine(vertex3, vertex1).HitTest2d(ptTest);
|
||
if (nHit3 == 5)
|
||
{
|
||
return HIT_SIDE3;
|
||
}
|
||
|
||
if (nHit1 == 1 && nHit2 == 1 && nHit3 == 1)
|
||
{
|
||
return HIT_INSIDE; //全部在左边,因此在内部
|
||
}
|
||
|
||
return HIT_OUTSIDE; //外部
|
||
}
|
||
|
||
GeTriangle::GeTriangle(const ADSGePoint3d &pt1, const ADSGePoint3d &pt2, const ADSGePoint3d &pt3, int nFlag)
|
||
: vertex1(pt1), vertex2(pt2), vertex3(pt3), m_nFlag(nFlag)
|
||
{
|
||
|
||
}
|
||
|
||
GeTriangle::~GeTriangle()
|
||
{
|
||
|
||
}
|
||
|
||
int GeTriangle::IsInvisible()
|
||
{
|
||
return (m_nFlag == SIDE1_INVISIBLE + SIDE2_INVISIBLE + SIDE3_INVISIBLE);
|
||
}
|
||
|
||
void GeTriangle::AsFace(Ge3DFace &face) const
|
||
{
|
||
face.SetVertex(0, vertex1);
|
||
face.SetVertex(3, vertex1);
|
||
face.SetVertex(1, vertex2);
|
||
face.SetVertex(2, vertex3);
|
||
|
||
face.SetVisible(0, !(m_nFlag & SIDE1_INVISIBLE));
|
||
face.SetVisible(1, !(m_nFlag & SIDE2_INVISIBLE));
|
||
face.SetVisible(2, !(m_nFlag & SIDE3_INVISIBLE));
|
||
}
|