Back to index

PHLine.C

 
//--------------------------------------------------------------------------------------- 
//  
// Includes:  PHLine.h 
// 
// Created by:  Jane M. Burward-Hoy and Federica Messer 
// 
// Purpose:  The constructor, destructor, copy constructor, and assignment functions are 
//           defined here for the PHLine class. 
//            
// Last update:  10/19/99 
// 
//------------------------------------------------------------------------------------ 
#include "PHLine.h" 
 
PHLine::PHLine() 
{ 
} 
 
PHLine::~PHLine() 
{ 
} 
 
PHLine::PHLine(const PHPoint &p,const PHVector &v) 
{ 
  // Basepoint is the line reference point 
  // Direction is the vector describing the direction of the line itself. 
 
  basepoint = p; 
  direction = v; 
} 
 
 
PHLine::PHLine(const PHPoint &p1,  const PHPoint &p2) 
{ 
  // Basepoint is the line reference point 
  // Direction is the vector connecting the two points 
   
  basepoint = p1; 
  direction = (PHVector)(p2 - p1); 
} 
 
PHLine::PHLine(const PHLine &rhs) 
{ 
  basepoint = rhs.basepoint; 
  direction = rhs.direction; 
} 
 
PHLine& PHLine::operator=(const PHLine &rhs) 
{ 
  basepoint = rhs.basepoint; 
  direction = rhs.direction; 
  return *this; 
} 
 
ostream&  operator<< (ostream &os, PHLine &line) 
{ 
  os << line.basepoint << " " << line.direction << endl; 
  return os; 
} 
 
void PHLine::print() const 
{ 
  cout << basepoint << " " << direction << endl; 
} 
 
// PHPoint PHLine::intersection(const PHLine& l2) const 
// { 
// // slightly modified version of DchGenLine.cc (takes only one argument) 
//   // "calculates the intersection of line l1 with the plane defined 
//   //  by line l2 (point,vector)" 
             
//   PHPoint p1, p2, I; 
//   PHVector v1, v2, p; 
//   double t, pi, theta1, theta2, theta3; 
   
//   pi = 3.1415; 
//   p2 = l2.basepoint;         
//   v2 = l2.direction;               
//   PHLine l1(basepoint, direction);   
//   p1 = l1.basepoint; 
//   v1 = l1.direction;        
 
//   p  = p2 - p1;        // vector between base points, relative 
//                        // to argument line 
//                       //move vector to origin 
//   cout << "vector between basepoints" << p << endl; 
 
//   theta1 = 180*v2.angle(v1)/pi; 
//       cout << "angle v2 and v1:  " << theta1 << endl; 
//   theta2 = 180*v2.angle(p)/pi; 
//       cout << "angle v2 + p " << theta2 << endl; 
//   theta3 = 180*v1.angle(p)/pi; 
//       cout << "angle v1 + p" << theta3 << endl; 
 
//   if (v2.dot(v1)!=0) 
 
//     { 
//       t = v2.dot(p)/v2.dot(v1); 
 
//       cout << "norm. dist. bet. B and I = " << t << endl; 
//       I = p1 + v1*t; 
 
//     } 
 
//  //  if ((v2.dot(v1)==0.0) && (v1.length()!=0.0)) //added case when 
// //     //v2 and v1 are perpendicular to each other 
// //     { 
// //       v1.normalize(); 
// //       t = p.dot(v1); 
// //       if (t < 0.0) t = -t; 
// //       I = p1 + v1*t; 
// //     } 
//   return I;       //return intersection point 
// } 
 
 
// PHPoint SteveIntersection( const PHLine& l1, const PHLine& l2) 
// // 
// // calculates the intersection of line l1  
// // with the plane defined by line l2 (point,vector)  
//     { 
//       PHPoint  p1,p2, I; 
//       PHVector v1,v2; 
//       p1 = l1.basepoint;    // base point of line 1 
//       v1 = l1.direction;   // direction vector of line 1 
//       p2 = l2.basepoint;    // base point of line 2 
//       v2 = l2.direction;   // direction vector of line 2 
 
//       PHVector  p; 
//       p  = p2 - p1;        // vector between base points 
//       cout << "Steve's vector between basepoints = " << p << endl; 
//       double t; 
//       t = (v2.dot(p))/(v2.dot(v1));   // normalized distance  
//                            //            of base point to intersection 
//       cout << "Steve's norm. dist. between B and I = " << t << endl; 
//       I = p1+v1*t;      // return intersection point 
//       return I; 
//     } 
 
// double PHLine::distToPoint(const PHPoint& p) const 
//   //slight modification of DchGenLine.cc 
// { 
//  PHLine line(p,direction); 
//  return p.dist(intersection(line)); 
// } 
 
// double PHLine::distToPointXY(const PHPoint& p) const 
// { 
// // slightly modified from DchGenLine.cc 
// // calculates  
// //    intersection of the line with the xy plane defined by point 
// //    and distance between intersection and point 
// //  
// // 
//     PHVector zhat(0,0,1);   // define vector in z direction 
//     PHLine plane(p,zhat);    // define line that describes xy 
//                                  // plane at point.z 
//     PHPoint p_intersect; 
//     p_intersect = intersection(plane);  // get point where line intersects with XY plane  
//     if (p_intersect.getX() < p.getX())  
//       { // intersecting point is to the right of point 
//        return p_intersect.dist(p);   
//       }  
//     else  
//       { 
//        return -p_intersect.dist(p);   
//       } 
// } 
 
// double PHLine::distToLine(const PHLine& l) const   
// {  
//   PHVector dir1 = l.direction; 
//   PHVector dir2 = direction; 
//   double theta = dir1.angle(dir2); 
//   double Distance; 
//   if(theta==0) 
//     { 
//       PHPoint HelpPoint = intersection(l); 
//       Distance = HelpPoint.dist(basepoint); 
//     } 
//   else 
//     { 
//       PHVector connection = dir1.cross(dir2); 
//       PHVector normal =  dir1.cross(connection); 
//       PHLine PlaneDefLine(l.basepoint,normal); 
//       PHPoint IntersectionPoint = intersection(PlaneDefLine); 
//       Distance = l.distToPoint(IntersectionPoint);         
//     } 
//   return Distance; 
// } 
 
 

Back to index