Files
EgtGeomKernel/CurveAux.cpp
T
Dario Sassi b4f2770eb8 EgtGeomKernel : Aggiunta prima versione distanza punto-arco.
Migliorie varie nei costruttori.
2014-01-02 07:54:39 +00:00

92 lines
2.8 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2013-2013
//----------------------------------------------------------------------------
// File : CurveAux.cpp Data : 22.11.13 Versione : 1.3a1
// Contenuto : Implementazione di alcune funzioni di utilità per le curve.
//
//
//
// Modifiche : 22.11.13 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include "CurveAux.h"
//----------------------------------------------------------------------------
bool
IsClosed( const ICurve& crvC)
{
Point3d ptStart ;
Point3d ptEnd ;
return ( crvC.GetStartPoint( ptStart) && crvC.GetEndPoint( ptEnd) && AreSamePointNear( ptStart, ptEnd)) ;
}
//----------------------------------------------------------------------------
bool
GetPointTang( const ICurve& crvC, double dU, ICurve::Side nS, Point3d& ptPos, Vector3d& vtTang)
{
if ( ! crvC.GetPointD1D2( dU, nS, ptPos, &vtTang))
return false ;
if ( vtTang.Normalize())
return true ;
// nel caso la derivata prima sia nulla, utilizziamo la seconda
Vector3d vtDummy ;
if ( ! crvC.GetPointD1D2( dU, nS, ptPos, &vtDummy, &vtTang))
return false ;
return vtTang.Normalize() ;
}
//----------------------------------------------------------------------------
bool
GetPointDiffGeom( const ICurve& crvC, double dU, ICurve::Side nS, CrvPointDiffGeom& oDiffG)
{
double dSqLenD1 ;
Point3d ptPos ;
Vector3d vtDer1 ;
Vector3d vtDer2 ;
if ( ! crvC.GetPointD1D2( dU, nS, ptPos, &vtDer1, &vtDer2))
return false ;
// assegno parametro e posizione
oDiffG.dU = dU ;
oDiffG.ptP = ptPos ;
// se esiste la derivata prima non nulla
dSqLenD1 = vtDer1.SqLen() ;
if ( vtDer1.Normalize()) {
oDiffG.vtT = vtDer1 ;
// del vettore deriv2^ tengo la sola componente perpendicolare al vettore tangente
oDiffG.vtN = vtDer2 - ( vtDer2 * vtDer1) * vtDer1 ;
if ( oDiffG.vtN.Normalize()) {
oDiffG.dCurv = ( vtDer1 ^ vtDer2).Len() / dSqLenD1 ;
oDiffG.nStatus = CrvPointDiffGeom::NCRV ;
}
else {
oDiffG.dCurv = 0 ;
oDiffG.nStatus = CrvPointDiffGeom::TANG ;
}
}
// se esiste almeno derivata seconda non nulla, definisce la tangente
else if ( vtDer2.Normalize()) {
oDiffG.vtT = vtDer2 ;
oDiffG.vtN.Set( 0, 0, 0) ;
oDiffG.dCurv = 0 ;
oDiffG.nStatus = CrvPointDiffGeom::TANG ;
}
// altrimenti non sono definite la tangente e la normale
else {
oDiffG.vtT.Set( 0, 0, 0) ;
oDiffG.vtN.Set( 0, 0, 0) ;
oDiffG.dCurv = 0 ;
oDiffG.nStatus = CrvPointDiffGeom::POS ;
}
return true ;
}