122
122
x = (TComp) valor;
123
123
y = (TComp) valor;
124
124
z = (TComp) valor;
129
129
//----------------------------------------------
131
//----------------------------------------------
133
/* Load from array (interpret ncomp components) */
134
template <class TipoComp> inline void Load(int ncomp, TipoComp* mem) {
135
for (int i = 0; i < 4; ++i) {
137
v[i] = (TComp) mem[i];
150
/* Store to array (interpret ncomp components) */
151
template <class TipoComp> inline void Store(int ncomp, TipoComp* mem) const {
152
for (int i = 0; i < 4; ++i) {
154
mem[i] = (TipoComp) v[i];
159
//----------------------------------------------
130
160
//-- Normas Vectoriales, Distancias y Producto Interior
131
161
//----------------------------------------------
191
221
return ((TReal)a.x * (TReal)b.x) + ((TReal)a.y * (TReal)b.y) + ((TReal)a.z * (TReal)b.z);
194
/* Devuelve el producto vectorial */
195
inline Vector3D ProductoVectorial(const Vector3D& b) const {
196
const Vector3D& a = *this;
224
/* Devuelve el producto vectorial
225
w = u x v = (u_y v_z - u_z v_y) i + (u_z v_x - u_x v_z) j + (u_x v_y - u_y v_x) k
227
| u.x u.y u.z | = { (u.y*v.z - u.z*v.y), (u.z*v.x - u.x*v.z), (u.x*v.y - u.y*v.x) }
230
inline Vector3D ProductoVectorial(const Vector3D& v) const {
231
const Vector3D& u = *this;
198
((TReal)a.y * (TReal)b.z) - ((TReal)b.y * (TReal)a.z),
199
((TReal)a.x * (TReal)b.z) - ((TReal)b.x * (TReal)a.z),
200
((TReal)a.x * (TReal)b.y) - ((TReal)b.x * (TReal)a.y)
233
((TReal)u.y * (TReal)v.z) - ((TReal)u.z * (TReal)v.y),
234
((TReal)u.z * (TReal)v.x) - ((TReal)u.x * (TReal)v.z),
235
((TReal)u.x * (TReal)v.y) - ((TReal)u.y * (TReal)v.x)
318
353
/* Devuelve el punto de la proyeccion ortogonal del punto sobre la recta definida por p0 y p1 */
319
inline Vector3D ProyeccionOrtogonalSobreRecta(const Vector3D& /*p0*/, const Vector3D& /*p1*/) const {
320
//return InterseccionEntreRectas(*this, *this + (p1-p0).VectorOrtogonal(), p0, p1);
354
inline Vector3D ProyeccionOrtogonalSobreRecta(const Vector3D& p0, const Vector3D& p1) const {
357
V::TComp proj = ( (*this) - p0).ProductoEscalar(vdir);
358
return p0 + (vdir * proj);
324
361
/* Devuelve la distancia del punto a la recta definida por p0 y p1 */
325
inline TReal DistanciaARecta(const Vector3D& /*p0*/, const Vector3D& /*p1*/) const {
326
//return (ProyeccionOrtogonalSobreRecta(p0, p1) - (*this)).Norma2();
362
inline TReal DistanciaARecta(const Vector3D& p0, const Vector3D& p1) const {
363
return (ProyeccionOrtogonalSobreRecta(p0, p1) - (*this)).Norma2();
331
366
/* Devuelve el cuadrado de la distancia del punto a la recta definida por p0 y p1 */
666
716
return Vector3D(x - valor, y - valor, z - valor);
720
inline Vector3D operator-() const {
721
return Vector3D(-x, -y, -z);
669
724
inline Vector3D& operator-=(const TComp& valor) {
693
750
x += (TComp) valor;
694
751
y += (TComp) valor;
695
752
z += (TComp) valor;
757
inline operator TComp *() {
761
inline operator const TComp *() const {
765
//----------------------------------------------
767
//----------------------------------------------
769
inline bool InsideOpenedBoundingBox(const Vector3D& p0, const Vector3D& p1) const {
774
vx = (p0.x < x && x < p1.x);
777
vx = (p1.x < x && x < p0.x);
781
vy = (p0.y < y && y < p1.y);
784
vy = (p1.y < y && y < p0.y);
788
vz = (p0.z < z && z < p1.z);
791
vz = (p1.z < z && z < p0.z);
794
return vx && vy && vz;
797
inline bool InsideClosedBoundingBox(const Vector3D& p0, const Vector3D& p1) const {
802
vx = (p0.x <= x && x <= p1.x);
805
vx = (p1.x <= x && x <= p0.x);
809
vy = (p0.y <= y && y <= p1.y);
812
vy = (p1.y <= y && y <= p0.y);
816
vz = (p0.z <= z && z <= p1.z);
819
vz = (p1.z <= z && z <= p0.z);
822
return vx && vy && vz;
825
inline void InitBoundingBox(Vector3D& p0, Vector3D& p1) const {
829
inline void InitBoundingBox(Vector3D bBox[2]) const {
830
InitBoundingBox(bBox[0], bBox[1]);
833
inline void ExtendBoundingBox(Vector3D& p0, Vector3D& p1) const {
884
inline void ExtendBoundingBox(Vector3D bBox[2]) const {
885
ExtendBoundingBox(bBox[0], bBox[1]);
699
888
//----------------------------------------------
701
890
//----------------------------------------------
912
template <class TipoComp> inline Vector3D operator+(const TipoComp val, const Vector3D& o) {
913
return Vector3D( (Vector3D::TComp)val + o.x, (Vector3D::TComp)val + o.y, (Vector3D::TComp)val + o.z );
916
template <class TipoComp> inline Vector3D operator-(const TipoComp val, const Vector3D& o) {
917
return Vector3D( (Vector3D::TComp)val - o.x, (Vector3D::TComp)val - o.y, (Vector3D::TComp)val - o.z );
920
template <class TipoComp> inline Vector3D operator*(const TipoComp val, const Vector3D& o) {
921
return Vector3D( (Vector3D::TComp)val * o.x, (Vector3D::TComp)val * o.y, (Vector3D::TComp)val * o.z );
924
template <class TipoComp> inline Vector3D operator/(const TipoComp val, const Vector3D& o) {
925
return Vector3D( (Vector3D::TComp)val / o.x, (Vector3D::TComp)val / o.y, (Vector3D::TComp)val / o.z );
723
928
class Matriz3x3 {