Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Doca.cxx

Go to the documentation of this file.
00001 
00008 #include "Doca.h"
00009 
00010 //
00011 // ini() is where all the real work gets done...
00012 //
00013 
00014 
00015 Doca::Doca(const Ray& ray1, 
00016            const Ray& ray2) 
00017            : P(ray1.position()), u(ray1.direction()), 
00018            Q(ray2.position()), v(ray2.direction()), 
00019            p1(p_nullRay)
00020 {
00021     ini();
00022 }
00023 
00024 Doca::Doca(const Point& point1, const Vector& vector1,
00025            const Point& point2, const Vector& vector2)
00026            : P(point1), u(vector1), Q(point2), v(vector2), 
00027            p1(p_nullRay)
00028 {
00029     ini();
00030 }
00031 
00032 void Doca::ini() {
00033 
00034     u = u.unit();
00035 
00036     m_mode = LINELINE;
00037     if(v.mag()==0.0) {
00038         m_mode = LINEPOINT;
00039         return;
00040     }
00041 
00042     v = v.unit();
00043 
00044     //Determine vector from start point track 1 to start of track 2
00045     Vector w     = P - Q;
00046 
00047     //Projections of of tracks along vector between start points
00048     double d     = u.dot(w);
00049     double e     = v.dot(w);
00050 
00051     //Dot product between two tracks to check if parallel
00052     double b     = u.dot(v);
00053     double denom = 1. - b*b;
00054 
00055     //Lines are not parallel
00056     if (fabs(b) < 1.)
00057     {
00058         s    = (b*e - d  ) / denom;
00059         t    = (e   - b*d) / denom;
00060         w    = w + s * u - t * v;
00061         doca = w.magnitude();
00062     }
00063     //Lines are parallel
00064     else
00065     {
00066         s    = 0;
00067         t    = d / b;
00068         w    = w - t * v;
00069         doca = w.magnitude();
00070     }
00071 }
00072 
00073 
00074 Point Doca::docaPointRay1()
00075 {
00076      return P + s * u;
00077 }
00078 
00079 Point Doca::docaPointRay2()
00080 {
00081     if(m_mode==LINEPOINT) return p_nullRay;
00082 
00083     return Q + t * v;
00084 }
00085 
00086 double Doca::docaOfPoint(const Point& p)
00087 {
00088     p1 = p;
00089     Vector dp =  p1 - P;
00090     s  = dp.dot(u);
00091 
00092     return (dp.cross(u)).mag();
00093 }

Generated on Tue Nov 18 14:08:42 2008 by doxygen 1.3.3