Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Line.cpp

    rf932b7 r69baa4  
    3737Line::~Line()
    3838{}
     39
     40Line &Line::operator=(const Line& rhs){
     41  if(this!=&rhs){
     42    origin.reset(new Vector(*rhs.origin));
     43    direction.reset(new Vector(*rhs.direction));
     44  }
     45  return *this;
     46}
    3947
    4048
     
    211219}
    212220
     221Line Line::rotateLine(const Line &rhs, double alpha) const{
     222  Vector lineOrigin = rotateVector(rhs.getOrigin(),alpha);
     223  Vector helper = rhs.getDirection();
     224  // rotate the direction without considering the ofset
     225  pair<Vector,Vector> parts = helper.partition(*direction);
     226  Vector lineDirection = parts.first;
     227  Vector a = parts.second;
     228  if(!a.IsZero()){
     229    // construct a vector that is orthogonal to a and direction and has length |a|
     230    Vector y = a;
     231    // direction is normalized, so the result has length |a|
     232    y.VectorProduct(*direction);
     233
     234    lineDirection += cos(alpha) * a + sin(alpha) * y;
     235  }
     236  return Line(lineOrigin,lineDirection);
     237}
     238
     239Plane Line::rotatePlane(const Plane &rhs, double alpha) const{
     240  vector<Vector> points = rhs.getPointsOnPlane();
     241  transform(points.begin(),
     242            points.end(),
     243            points.begin(),
     244            boost::bind(&Line::rotateVector,this,_1,alpha));
     245  return Plane(points[0],points[1],points[2]);
     246}
     247
    213248Plane Line::getOrthogonalPlane(const Vector &origin) const{
    214249  return Plane(getDirection(),origin);
     
    234269}
    235270
     271LinePoint Line::getLinePoint(const Vector &point) const{
     272  ASSERT(isContained(point),"Line point queried for point not on line");
     273  Vector helper = point - (*origin);
     274  double param = helper.ScalarProduct(*direction);
     275  return LinePoint(*this,param);
     276}
     277
     278LinePoint Line::posEndpoint() const{
     279  return LinePoint(*this, numeric_limits<double>::infinity());
     280}
     281LinePoint Line::negEndpoint() const{
     282  return LinePoint(*this,-numeric_limits<double>::infinity());
     283}
     284
     285bool operator==(const Line &x,const Line &y){
     286  return *x.origin == *y.origin && *x.direction == *y.direction;
     287}
     288
    236289Line makeLineThrough(const Vector &x1, const Vector &x2){
    237290  if(x1==x2){
     
    240293  return Line(x1,x1-x2);
    241294}
     295
     296
     297/******************************** Points on the line ********************/
     298
     299LinePoint::LinePoint(const LinePoint &src) :
     300  line(src.line),param(src.param)
     301{}
     302
     303LinePoint::LinePoint(const Line &_line, double _param) :
     304  line(_line),param(_param)
     305{}
     306
     307LinePoint& LinePoint::operator=(const LinePoint &src){
     308  line=src.line;
     309  param=src.param;
     310  return *this;
     311}
     312
     313Vector LinePoint::getPoint() const{
     314  ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called");
     315  return (*line.origin)+param*(*line.direction);
     316}
     317
     318Line LinePoint::getLine() const{
     319  return line;
     320}
     321
     322bool LinePoint::isInfinite() const{
     323  return isPosInfinity() || isNegInfinity();
     324}
     325bool LinePoint::isPosInfinity() const{
     326  return param == numeric_limits<double>::infinity();
     327}
     328bool LinePoint::isNegInfinity() const{
     329  return param ==-numeric_limits<double>::infinity();
     330}
     331
     332bool operator==(const LinePoint &x, const LinePoint &y){
     333  ASSERT(x.line==y.line,"Operation on two points of different lines");
     334  return x.param == y.param;
     335
     336}
     337bool operator<(const LinePoint &x, const LinePoint &y){
     338  ASSERT(x.line==y.line,"Operation on two points of different lines");
     339  return x.param<y.param;
     340}
Note: See TracChangeset for help on using the changeset viewer.