comparison Framework/Toolbox/GeometryToolbox.cpp @ 157:2309e8d86efe wasm

IntersectPlaneAndLine
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 09 Feb 2018 16:00:29 +0100
parents 441cfe8e7440
children a053ca7fa5c6
comparison
equal deleted inserted replaced
156:441cfe8e7440 157:2309e8d86efe
34 { 34 {
35 void Print(const Vector& v) 35 void Print(const Vector& v)
36 { 36 {
37 for (size_t i = 0; i < v.size(); i++) 37 for (size_t i = 0; i < v.size(); i++)
38 { 38 {
39 printf("%8.2f\n", v[i]); 39 printf("%g\n", v[i]);
40 //printf("%8.2f\n", v[i]);
40 } 41 }
41 printf("\n"); 42 printf("\n");
42 } 43 }
43 44
44 45
46 { 47 {
47 for (size_t i = 0; i < m.size1(); i++) 48 for (size_t i = 0; i < m.size1(); i++)
48 { 49 {
49 for (size_t j = 0; j < m.size2(); j++) 50 for (size_t j = 0; j < m.size2(); j++)
50 { 51 {
51 printf("%8.2f ", m(i,j)); 52 printf("%g ", m(i,j));
53 //printf("%8.2f ", m(i,j));
52 } 54 }
53 printf("\n"); 55 printf("\n");
54 } 56 }
57 printf("\n");
55 } 58 }
56 59
57 60
58 bool ParseVector(Vector& target, 61 bool ParseVector(Vector& target,
59 const std::string& value) 62 const std::string& value)
482 } 485 }
483 } 486 }
484 } 487 }
485 488
486 489
490 bool IntersectPlaneAndLine(Vector& p,
491 const Vector& normal,
492 double d,
493 const Vector& origin,
494 const Vector& direction)
495 {
496 // http://geomalgorithms.com/a05-_intersect-1.html#Line-Plane-Intersection
497
498 // Check for parallel line and plane
499 double denominator = boost::numeric::ublas::inner_prod(direction, normal);
500
501 if (fabs(denominator) < 100.0 * std::numeric_limits<double>::epsilon())
502 {
503 return false;
504 }
505 else
506 {
507 // Compute intersection
508 double t = -(normal[0] * origin[0] +
509 normal[1] * origin[1] +
510 normal[2] * origin[2] + d) / denominator;
511
512 p = origin + t * direction;
513 return true;
514 }
515 }
516
517
487 void FillMatrix(Matrix& target, 518 void FillMatrix(Matrix& target,
488 size_t rows, 519 size_t rows,
489 size_t columns, 520 size_t columns,
490 const double values[]) 521 const double values[])
491 { 522 {