4056be90d9
- modifiche a IntersLineBox e IntersPlaneBox - adattamenti conseguenti.
90 lines
3.1 KiB
C++
90 lines
3.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2020-2020
|
|
//----------------------------------------------------------------------------
|
|
// File : IntersPlaneBox.cpp Data : 07.05.20 Versione : 2.2e1
|
|
// Contenuto : Implementazione della intersezione piano/box.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 07.05.20 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "SurfTriMesh.h"
|
|
#include "/EgtDev/Include/EGkIntersPlaneBox.h"
|
|
#include "/EgtDev/Include/EGkIntersPlaneSurfTm.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Box e piano devono essere nello stesso riferimento. Il box deve essere axis aligned.
|
|
bool
|
|
TestIntersPlaneBox( const Plane3d& plPlane, const BBox3d& b3Box)
|
|
{
|
|
// Verifica del piano
|
|
if ( ! plPlane.IsValid())
|
|
return false ;
|
|
// Centro e estensione del box
|
|
Point3d ptCen ;
|
|
Vector3d vtExt ;
|
|
if ( ! b3Box.GetCenterExtent( ptCen, vtExt))
|
|
return false ;
|
|
// Distanza del centro dal piano
|
|
double dDist = DistPointPlane( ptCen, plPlane) ;
|
|
// Proiezione dell'estensione sulla normale al piano
|
|
Vector3d vtN = plPlane.GetVersN() ;
|
|
double dProjExt = vtExt.x * abs( vtN.x) + vtExt.y * abs( vtN.y) + vtExt.z * abs( vtN.z) ;
|
|
// Confronto distanza del centro con estensione proiettata
|
|
return ( abs( dDist) < dProjExt + EPS_SMALL) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
IntersPlaneBox( const Plane3d& plPlane, const BBox3d& b3Box,
|
|
PNTVECTOR& vPnt, BIPNTVECTOR& vBpt, TRIA3DVECTOR& vTria)
|
|
{
|
|
// Verifico il piano
|
|
if ( ! plPlane.IsValid())
|
|
return false ;
|
|
// Recupero i dati del Box
|
|
Point3d ptMin ;
|
|
double dDimX, dDimY, dDimZ ;
|
|
if ( ! b3Box.GetMinDim( ptMin, dDimX, dDimY, dDimZ))
|
|
return false ;
|
|
// Pulisco vettori intersezioni
|
|
vPnt.clear() ;
|
|
vBpt.clear() ;
|
|
vTria.clear() ;
|
|
// Verifico se può esistere intersezione
|
|
if ( ! TestIntersPlaneBox( plPlane, b3Box))
|
|
return true ;
|
|
// Contorno di base
|
|
PolyLine PL ;
|
|
PL.AddUPoint( 0, ptMin) ;
|
|
PL.AddUPoint( 1, ptMin + Vector3d( dDimX, 0, 0)) ;
|
|
PL.AddUPoint( 2, ptMin + Vector3d( dDimX, dDimY, 0)) ;
|
|
PL.AddUPoint( 3, ptMin + Vector3d( 0, dDimY, 0)) ;
|
|
PL.Close() ;
|
|
// Vettore altezza
|
|
Vector3d vtExtr( 0, 0, dDimZ) ;
|
|
// Creo la superficie trimesh equivalente
|
|
SurfTriMesh Stm ;
|
|
if ( ! Stm.CreateByExtrusion( PL, vtExtr))
|
|
return false ;
|
|
SurfTriMesh StmBot ;
|
|
if ( ! StmBot.CreateByFlatContour( PL))
|
|
return false ;
|
|
StmBot.Invert() ;
|
|
SurfTriMesh StmTop ;
|
|
if ( ! StmTop.CreateByFlatContour( PL))
|
|
return false ;
|
|
StmTop.Translate( vtExtr) ;
|
|
if ( ! Stm.DoSewing( StmBot) || ! Stm.DoSewing( StmTop))
|
|
return false ;
|
|
// Calcolo l'intersezione
|
|
return IntersPlaneSurfTm( plPlane, Stm, vPnt, vBpt, vTria) ;
|
|
}
|