//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : IntersLinePlane.cpp Data : 18.02.15 Versione : 1.6b7 // Contenuto : Implementazione della intersezione linea/piano. // // // // Modifiche : 18.02.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "/EgtDev/Include/EGkIntersLinePlane.h" //---------------------------------------------------------------------------- int IntersLinePlane( const Point3d& ptL1, const Point3d& ptL2, const Plane3d& plPlane, Point3d& ptInt, bool bFinite) { Vector3d vtL = ptL2 - ptL1 ; double dLen = vtL.Len() ; if ( dLen > EPS_SMALL) vtL /= dLen ; else vtL = V_NULL ; return IntersLinePlane( ptL1, vtL, dLen, plPlane, ptInt, bFinite) ; } //---------------------------------------------------------------------------- int IntersLinePlane( const Point3d& ptL, const Vector3d& vtL, double dLen, const Plane3d& plPlane, Point3d& ptInt, bool bFinite) { Vector3d vtDir = vtL ; if ( dLen > EPS_SMALL && ! vtDir.Normalize( EPS_ZERO)) return ILPT_NO ; // coseno dell'angolo tra direzione linea e normale al piano double dCosAng = vtDir * plPlane.GetVersN() ; // posizione del punto rispetto al piano double dPosL = ( ptL - ORIG) * plPlane.GetVersN() - plPlane.GetDist() ; // verifico se linea parallela al piano (ovvero ortogonale alla normale) if ( abs( dCosAng) < COS_ORTO_ANG_ZERO) { // se il punto giace nel piano, vi giace anche la linea if ( abs( dPosL) < EPS_SMALL) return ILPT_INPLANE ; // alrimenti paralleli e non ci sono intersezioni else return ILPT_NO ; } // determino il punto di intersezione double dDistI = - dPosL / dCosAng ; ptInt = ptL + vtDir * dDistI ; // se linea infinita, ho trovato l'intersezione if ( ! bFinite) return ILPT_YES ; // intersezione sul primo estremo if ( abs( dDistI) < EPS_SMALL) return ILPT_START ; // intersezione sul secondo estremo else if ( abs( dDistI - dLen) < EPS_SMALL) return ILPT_END ; // intersezione interna else if ( dDistI > 0 && dDistI < dLen) return ILPT_YES ; // nessuna intersezione else return ILPT_NO ; }