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>
41 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
48 // calculate a vector "u1" representing the shortest distance from
49 // the plane specified by normal and v0 to a point specified by
50 // "vec". "u1" represents both the direction and magnitude of
51 // this desired distance.
53 // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
57 ( sgScalarProductVec3(normal, vec) /
58 sgScalarProductVec3(normal, normal)
62 // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
63 // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
64 // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
66 // calculate the vector "v" which is the vector "vec" mapped onto
67 // the plane specified by "normal" and "v0".
71 sgAddVec3(tmp, v0, vec);
72 sgSubVec3(v, tmp, u1);
73 // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
75 // Calculate the vector "result" which is "v" - "v0" which is a
76 // directional vector pointing from v0 towards v
80 sgSubVec3(result, v, v0);
81 // printf(" result = %.2f, %.2f, %.2f\n",
82 // result[0], result[1], result[2]);
86 // Given a point p, and a line through p0 with direction vector d,
87 // find the shortest distance (squared) from the point to the line
88 double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0,
91 // Given a point p, and a line through p0 with direction vector d,
92 // find the shortest distance (squared) from the point to the line
93 double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0,