41a38fef3b
- aggiunta entità testo (con font Nfe e di sistema) - in tutte le rotate ora l'angolo è in gradi - aggiunta trasformazione Shear (scorrimento) - aggiunta trsformazione LocToLoc - Set/GetInfo specializzate per i diversi tipi di informazioni - Copy e Relocate con possibilità di indicare l'entità di riferimento rispetto a cui inserire - aggiunte trasformazioni a PolyLine.
183 lines
5.7 KiB
C++
183 lines
5.7 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2013
|
|
//----------------------------------------------------------------------------
|
|
// File : Point3d.cpp Data : 20.11.13 Versione : 1.3a1
|
|
// Contenuto : Funzioni della classe Punto 3d.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 04.01.13 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "\EgtDev\Include\EGkPoint3d.h"
|
|
#include "\EgtDev\Include\EGkFrame3d.h"
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Traslazione
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
Point3d::Translate( const Vector3d& vtMove)
|
|
{
|
|
*this = *this + vtMove ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Rotazione
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dAngDeg)
|
|
{
|
|
double dAngRad = dAngDeg * DEGTORAD ;
|
|
return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Rotazione
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
|
|
{
|
|
// vettore dall'asse al punto
|
|
Vector3d vtDiff = *this - ptAx ;
|
|
if ( vtDiff.IsZero())
|
|
return true ;
|
|
|
|
// rotazione del vettore
|
|
if ( ! vtDiff.Rotate( vtAx, dCosAng, dSinAng))
|
|
return false ;
|
|
|
|
// ricostruisco il punto
|
|
*this = ptAx + vtDiff ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Scalatura non uniforme
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double dCoeffZ)
|
|
{
|
|
// vettore dal centro al punto
|
|
Vector3d vtDiff = *this - frRef.Orig() ;
|
|
if ( vtDiff.IsZero())
|
|
return true ;
|
|
|
|
// scalatura del vettore
|
|
if ( ! vtDiff.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ))
|
|
return false ;
|
|
|
|
// ricostruisco il punto
|
|
*this = frRef.Orig() + vtDiff ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Specchiatura
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
|
|
{
|
|
// vettore dal riferimento al punto
|
|
Vector3d vtDiff = *this - ptOn ;
|
|
if ( vtDiff.IsZero())
|
|
return true ;
|
|
|
|
// specchiatura del vettore
|
|
if ( ! vtDiff.Mirror( vtNorm))
|
|
return false ;
|
|
|
|
// ricostruisco il punto
|
|
*this = ptOn + vtDiff ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Scorrimento
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d& vtDir, double dCoeff)
|
|
{
|
|
// vettore dal riferimento al punto
|
|
Vector3d vtDiff = *this - ptOn ;
|
|
if ( vtDiff.IsZero())
|
|
return true ;
|
|
|
|
// ricostruisco il punto
|
|
*this += dCoeff * ( vtDiff * vtNorm) * vtDir ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Cambio di riferimento : dal riferimento al globale
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::ToGlob( const Frame3d& frRef)
|
|
{
|
|
// verifico validità del frame
|
|
if ( frRef.GetType() == Frame3d::ERR)
|
|
return false ;
|
|
|
|
// eseguo trasformazione
|
|
if ( frRef.GetType() != Frame3d::TOP) {
|
|
Point3d ptT( x, y, z) ;
|
|
x = ptT.x * frRef.VersX().x + ptT.y * frRef.VersY().x + ptT.z * frRef.VersZ().x + frRef.Orig().x ;
|
|
y = ptT.x * frRef.VersX().y + ptT.y * frRef.VersY().y + ptT.z * frRef.VersZ().y + frRef.Orig().y ;
|
|
z = ptT.x * frRef.VersX().z + ptT.y * frRef.VersY().z + ptT.z * frRef.VersZ().z + frRef.Orig().z ;
|
|
}
|
|
else {
|
|
x += frRef.Orig().x ;
|
|
y += frRef.Orig().y ;
|
|
z += frRef.Orig().z ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Cambio di riferimento : dal globale al riferimento
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::ToLoc( const Frame3d& frRef)
|
|
{
|
|
// verifico validità del frame
|
|
if ( frRef.GetType() == Frame3d::ERR)
|
|
return false ;
|
|
|
|
// eseguo trasformazione
|
|
if ( frRef.GetType() != Frame3d::TOP) {
|
|
Vector3d vtT( x - frRef.Orig().x, y - frRef.Orig().y, z - frRef.Orig().z) ;
|
|
x = vtT.x * frRef.VersX().x + vtT.y * frRef.VersX().y + vtT.z * frRef.VersX().z ;
|
|
y = vtT.x * frRef.VersY().x + vtT.y * frRef.VersY().y + vtT.z * frRef.VersY().z ;
|
|
z = vtT.x * frRef.VersZ().x + vtT.y * frRef.VersZ().y + vtT.z * frRef.VersZ().z ;
|
|
}
|
|
else {
|
|
x -= frRef.Orig().x ;
|
|
y -= frRef.Orig().y ;
|
|
z -= frRef.Orig().z ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
// Cambio di riferimento : dal primo riferimento al secondo
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Point3d::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
|
|
{
|
|
// se i due riferimenti coincidono, non devo fare alcunché
|
|
if ( AreSameFrame( frOri, frDest))
|
|
return true ;
|
|
|
|
return ( ToGlob( frOri) && ToLoc( frDest)) ;
|
|
}
|