07b1f21ecd
- aggiunta IntersSurfTmSurfTm - correzioni a HashGrids.
64 lines
2.3 KiB
C++
64 lines
2.3 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2017-2017
|
|
//----------------------------------------------------------------------------
|
|
// File : IntersPlaneTria.cpp Data : 16.10.17 Versione : 1.8j3
|
|
// Contenuto : Implementazione della intersezione piano/triangolo.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 16.10.17 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "IntersLineTria.h"
|
|
#include "/EgtDev/Include/EGkIntersPlaneTria.h"
|
|
#include "/EgtDev/Include/EGkIntersPlanePlane.h"
|
|
#include <array>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
IntersPlaneTria( const Plane3d& plPlane, const Triangle3d& trTria, Point3d& ptInt, Point3d& ptInt2)
|
|
{
|
|
// calcolo le distanze dei vertici del triangolo dal piano
|
|
array< double, 3> vDist ;
|
|
for ( int i = 0 ; i < 3 ; ++i)
|
|
vDist[i] = ( ( trTria.GetP( i) - ORIG) * plPlane.GetVersN() - plPlane.GetDist()) ;
|
|
// verifico posizione del triangolo rispetto al piano
|
|
int nVertPos = 0 ; int nVertNeg = 0 ;
|
|
for ( auto& dDist : vDist) {
|
|
if ( dDist > EPS_SMALL)
|
|
++ nVertPos ;
|
|
else if ( dDist < -EPS_SMALL)
|
|
++ nVertNeg ;
|
|
}
|
|
// se il triangolo giace nel piano, sovrapposizione
|
|
if ( nVertPos == 0 && nVertNeg == 0)
|
|
return IPTT_OVERLAPS ;
|
|
// se altrimenti il triangolo giace tutto da una parte del piano, nessuna intersezione
|
|
else if ( nVertPos == 3 || nVertNeg == 3)
|
|
return IPTT_NO ;
|
|
|
|
// intersezione tra il piano e il piano del triangolo
|
|
Plane3d plTria ;
|
|
plTria.Set( trTria.GetP( 0), trTria.GetN()) ;
|
|
Point3d ptL ; Vector3d vtL ;
|
|
if ( IntersPlanePlane( plPlane, plTria, ptL, vtL) != IPPT_YES)
|
|
return IPTT_NO ;
|
|
|
|
// interseco la linea con il triangolo (giace nel suo piano)
|
|
int nRes = IntersCoplanarLineTria( ptL, vtL, 100.0, trTria, ptInt, ptInt2, false) ;
|
|
switch ( nRes) {
|
|
case ILTT_NO : return IPTT_NO ;
|
|
case ILTT_SEGM : return IPTT_YES ;
|
|
case ILTT_SEGM_ON_EDGE : return IPTT_EDGE ;
|
|
case ILTT_VERT : return IPTT_VERT ;
|
|
case ILTT_EDGE : return IPTT_NO ;
|
|
default : return IPTT_NO ;
|
|
}
|
|
}
|