1 // vector.hxx -- additional vector routines
3 // Written by Curtis Olson, started December 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 # error This library requires C++
36 #include <simgear/compiler.h>
40 #include <simgear/mat3.h>
43 // Map a vector onto the plane specified by normal
44 void map_vec_onto_cur_surface_plane( MAT3vec normal,
50 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
57 // calculate a vector "u1" representing the shortest distance from
58 // the plane specified by normal and v0 to a point specified by
59 // "vec". "u1" represents both the direction and magnitude of
60 // this desired distance.
62 // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
66 ( sgScalarProductVec3(normal, vec) /
67 sgScalarProductVec3(normal, normal)
71 // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
72 // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
73 // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
75 // calculate the vector "v" which is the vector "vec" mapped onto
76 // the plane specified by "normal" and "v0".
80 sgAddVec3(tmp, v0, vec);
81 sgSubVec3(v, tmp, u1);
82 // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
84 // Calculate the vector "result" which is "v" - "v0" which is a
85 // directional vector pointing from v0 towards v
89 sgSubVec3(result, v, v0);
90 // printf(" result = %.2f, %.2f, %.2f\n",
91 // result[0], result[1], result[2]);
95 // Given a point p, and a line through p0 with direction vector d,
96 // find the shortest distance from the point to the line
97 double fgPointLine(MAT3vec p, MAT3vec p0, MAT3vec d);
100 // Given a point p, and a line through p0 with direction vector d,
101 // find the shortest distance (squared) from the point to the line
102 double fgPointLineSquared(MAT3vec p, MAT3vec p0, MAT3vec d);
105 // Given a point p, and a line through p0 with direction vector d,
106 // find the shortest distance (squared) from the point to the line
107 double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0,
110 // Given a point p, and a line through p0 with direction vector d,
111 // find the shortest distance (squared) from the point to the line
112 double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
116 #endif // _VECTOR_HXX