b50b676249
Aggiunte costanti geometriche locali.
132 lines
4.1 KiB
C++
132 lines
4.1 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"
|
|
#include "GeoConst.h"
|
|
#include "/EgtDev/Include/EgkCurveComposite.h"
|
|
#include "/EgtDev/Include/EgkCurveBezier.h"
|
|
#include "/EgtDev/Include/EgkCurveArc.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.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 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ArcToBezierCurve( const ICurve* pCrv, ICurve*& pCrvNew)
|
|
{
|
|
// verifico sia un arco
|
|
const ICurveArc* pArc = GetCurveArc( pCrv) ;
|
|
if ( pArc == nullptr)
|
|
return false ;
|
|
|
|
// se angolo al centro sotto il limite, basta una curva
|
|
if ( fabs( pArc->GetAngCenter()) <= BEZARC_ANG_CEN_MAX) {
|
|
// creo la curva di Bezier
|
|
PtrOwner<ICurveBezier> pCrvBez( CreateCurveBezier()) ;
|
|
if ( ! IsValid( pCrvBez))
|
|
return false ;
|
|
if ( ! pCrvBez->FromArc( *pArc))
|
|
return false ;
|
|
// restituisco la curva
|
|
pCrvNew = Release( pCrvBez) ;
|
|
}
|
|
|
|
// altrimenti curva composita di Bezier
|
|
else {
|
|
// creo la curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( ! IsValid( pCrvCompo))
|
|
return false ;
|
|
if ( ! pCrvCompo->AddCurve( *pArc) ||
|
|
! pCrvCompo->ArcsToBezierCurves())
|
|
return false ;
|
|
// restituisco la curva
|
|
pCrvNew = Release( pCrvCompo) ;
|
|
}
|
|
|
|
return true ;
|
|
} |