Files
EgtGeomKernel/Point3d.cpp
T
Dario Sassi 4ebb43bf1e EgtGeomKernel 1.5a6 : prima versione di scalatura non uniforme,
aggiunto comando COUNTER in tsc.
2014-01-19 11:19:56 +00:00

161 lines
4.8 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 dAngRad)
{
return Rotate( ptAx, vtAx, cos( dAngRad), sin( dAngRad)) ;
}
//----------------------------------------------------------------------------
// Rotazione
//----------------------------------------------------------------------------
bool
Point3d::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, double dSinAng)
{
Vector3d vtDiff ;
// vettore dall'asse al punto
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)
{
Vector3d vtDiff ;
// vettore dal centro al punto
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)
{
Vector3d vtDiff ;
// vettore dal riferimento al punto
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 ;
}
//----------------------------------------------------------------------------
// 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 ;
}