Changes in src/Line.cpp [f932b7:69baa4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Line.cpp
rf932b7 r69baa4 37 37 Line::~Line() 38 38 {} 39 40 Line &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 } 39 47 40 48 … … 211 219 } 212 220 221 Line 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 239 Plane 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 213 248 Plane Line::getOrthogonalPlane(const Vector &origin) const{ 214 249 return Plane(getDirection(),origin); … … 234 269 } 235 270 271 LinePoint 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 278 LinePoint Line::posEndpoint() const{ 279 return LinePoint(*this, numeric_limits<double>::infinity()); 280 } 281 LinePoint Line::negEndpoint() const{ 282 return LinePoint(*this,-numeric_limits<double>::infinity()); 283 } 284 285 bool operator==(const Line &x,const Line &y){ 286 return *x.origin == *y.origin && *x.direction == *y.direction; 287 } 288 236 289 Line makeLineThrough(const Vector &x1, const Vector &x2){ 237 290 if(x1==x2){ … … 240 293 return Line(x1,x1-x2); 241 294 } 295 296 297 /******************************** Points on the line ********************/ 298 299 LinePoint::LinePoint(const LinePoint &src) : 300 line(src.line),param(src.param) 301 {} 302 303 LinePoint::LinePoint(const Line &_line, double _param) : 304 line(_line),param(_param) 305 {} 306 307 LinePoint& LinePoint::operator=(const LinePoint &src){ 308 line=src.line; 309 param=src.param; 310 return *this; 311 } 312 313 Vector LinePoint::getPoint() const{ 314 ASSERT(!isInfinite(),"getPoint() on infinite LinePoint called"); 315 return (*line.origin)+param*(*line.direction); 316 } 317 318 Line LinePoint::getLine() const{ 319 return line; 320 } 321 322 bool LinePoint::isInfinite() const{ 323 return isPosInfinity() || isNegInfinity(); 324 } 325 bool LinePoint::isPosInfinity() const{ 326 return param == numeric_limits<double>::infinity(); 327 } 328 bool LinePoint::isNegInfinity() const{ 329 return param ==-numeric_limits<double>::infinity(); 330 } 331 332 bool 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 } 337 bool 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.