1 // vector.cxx -- 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.
27 // #include <Include/fg_types.h>
32 // Given a point p, and a line through p0 with direction vector d,
33 // find the shortest distance (squared) from the point to the line
34 double sgPointLineDistSquared( const sgVec3 p, const sgVec3 p0,
43 // calculate the projection, u1, of u along d.
44 // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
45 ud = sgScalarProductVec3(u, d);
46 dd = sgScalarProductVec3(d, d);
49 sgScaleVec3(u1, d, tmp);;
51 // v = u - u1 = vector from closest point on line, p1, to the
55 return ( sgScalarProductVec3(v, v) );
59 // Given a point p, and a line through p0 with direction vector d,
60 // find the shortest distance (squared) from the point to the line
61 double sgdPointLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
70 // calculate the projection, u1, of u along d.
71 // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
72 ud = sgdScalarProductVec3(u, d);
73 dd = sgdScalarProductVec3(d, d);
76 sgdScaleVec3(u1, d, tmp);;
78 // v = u - u1 = vector from closest point on line, p1, to the
82 return ( sgdScalarProductVec3(v, v) );