We have a 'divide by zero' situation in simgear/math/vector.cxx, but I'm
sure what the right fix is.  Here's the offending routine:


// Given a point p, and a line through p0 with direction vector d,
// find the shortest distance (squared) from the point to the line
double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
                                         const sgdVec3 d ) {

    sgdVec3 u, u1, v;

    // u = p - p0
    sgdSubVec3(u, p, p0);
    // calculate the projection, u1, of u along d.
    // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
    double ud = sgdScalarProductVec3(u, d);
    double dd = sgdScalarProductVec3(d, d);
    double tmp = ud / dd;

    sgdScaleVec3(u1, d, tmp);;

    // v = u - u1 = vector from closest point on line, p1, to the
    // original point, p.
    sgdSubVec3(v, u, u1);

    return ( sgdScalarProductVec3(v, v) );
}


The problem is that the formula used here only works for nonzero
vectors (according to my old Linear Algebra textbook).  Since

  dot_prod(u,v) = dot_prod(v,u)

if u or d equal zero, we need to do something different.  I'd suggest
something like:

  ...
  double tmp;

  // u = p - p0
  sgdSubVec3(u, p, p0);

  if (sgIsZeroVec3(u) || sgIsZeroVec3(d)) {
    tmp = 0;
  } else {
    // calculate the projection, u1, of u along d.
    // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d;
    double ud = sgdScalarProductVec3(u, d);
    double dd = sgdScalarProductVec3(d, d);
    tmp = ud / dd;
  }

  sgdScaleVec3(u1, d, tmp);
  ...

There's no such thing as sgIsZeroVec3() right now.  This would
effectively fix the FPE, but is the vector math correct?  Is setting
tmp=0 a proper fix?

Thanks
-- 
Cameron Moore
/ One cannot guess the real difficulties \
\  of a problem before having solved it. /

_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to