Algorithmic geometry. More...
Classes | |
class | Quaternion |
Implements the quaternion operations. More... | |
Typedefs | |
typedef util::Matrix < 2, 2, double > | Matrix2d |
Type of 2x2 matrix. | |
typedef util::Matrix < 3, 3, double > | Matrix3d |
Type of 3x3 matrix. | |
typedef util::Matrix < 4, 4, double > | Matrix4d |
Type of a 4x4 matrix. | |
typedef util::Vector< 2, double > | Point2d |
Type of a 2D point. | |
typedef util::Vector< 3, double > | Point3d |
Type of a 3D point. | |
typedef util::Vector< 4, double > | Point4d |
Type of a 4D point. | |
Functions | |
Point3d | barycentricToCartesian (const Point3d &barycentric, const Point3d &p1, const Point3d &p2, const Point3d &p3) |
Convert barycentric coordinates to cartesian. | |
Matrix3d | barycentricToCartesian_matrix (const Point3d &p1, const Point3d &p2, const Point3d &p3) |
Convert cartesian coordinates to barycentric coordinates in a triangle. | |
Point3d | cartesianToBarycentric (const Point3d &pos, const Point3d &p1, const Point3d &p2, const Point3d &p3) |
Convert cartesian coordinates to barycentric coordinates in a triangle. | |
Matrix3d | cartesianToBarycentric_matrix (const Point3d &p1, const Point3d &p2, const Point3d &p3, int &index_one) |
Convert cartesian coordinates to barycentric coordinates in a triangle. | |
Point2d | centroid (const std::vector< Point2d > &polygon) |
Center of mass of a 2D non-overlapping polygon. | |
bool | lineLineIntersection (Point2d &u, const Point2d &p1, const Point2d &u1, const Point2d &p2, const Point2d &u2) |
Find if the segment [p1,p2] intersect the line going through p of normal n. | |
bool | lineSegmentIntersection (Point2d &u, const Point2d &p1, const Point2d &p2, const Point2d &p, const Point2d &n) |
Find if the segment [p1,p2] intersect the line going through p of normal n. | |
bool | lineTriangleIntersection (Point3d &u, double &s, const Point3d &p1, const Point3d &p2, const Point3d &tr1, const Point3d &tr2, const Point3d &tr3) |
Line-triangle intersection. | |
Quaternion | operator* (const Quaternion &q, double s) |
Quaternion | operator* (double s, const Quaternion &q) |
bool | planeLineIntersection (Point3d &u, double &s, const Point3d &p, const Point3d &n, const Point3d &u1, const Point3d &u2) |
Plane-Line Intersection. | |
template<typename PointContainer > | |
bool | pointInPolygon (const Point2d &p, const PointContainer &polygon) |
bool | pointInPolygon (const Point2d &p, const std::vector< Point2d > &polygon) |
Find if the point p is inside the polygon using the winding number. | |
bool | pointInTriangle (Point3d &u, double &s, const Point3d &p, const Point3d &p1, const Point3d &p2, const Point3d &p3) |
Point in triangle test (3D). | |
bool | pointInTriangle (const Point2d &p, const Point2d &p1, const Point2d &p2, const Point2d &p3) |
Point in triangle test (2D). | |
template<size_t N> | |
double | polygonArea (const std::vector< util::Vector< N, double > > &polygon) |
Area of a planar polygon. | |
template<size_t N> | |
util::Vector< N, double > | projectPointOnLine (const util::Vector< N, double > &pt, const util::Vector< N, double > &u1, const util::Vector< N, double > &u2, bool strict=false) |
Project a point on a line. | |
Point3d | projectPointOnPlane (const Point3d &pos, const Point3d &p, const Point3d &n) |
Project a point into a plane defined by a point and a normal to the plane. | |
Point3d | projectPointOnTriangle (const Point3d &pt, const Point3d &p1, const Point3d &p2, const Point3d &p3, double &s, bool *in_triangle=0) |
Project a point into a triangle. | |
bool | segmentSegmentIntersection (Point2d &u, const Point2d &p1, const Point2d &p2, const Point2d &q1, const Point2d &q2) |
Find if two 2D segments intersect. | |
Quaternion | slerp (const Quaternion &q1, const Quaternion &q2, double t) |
template<size_t N> | |
double | triangleArea (const util::Vector< N, double > &a, const util::Vector< N, double > &b, const util::Vector< N, double > &c) |
Area of a triangle in 2D or 3D. |
Algorithmic geometry.
This namespace contains different usefull geometry algorithms, like intersections, areas, ...
typedef util::Matrix<2,2,double> geometry::Matrix2d |
Type of 2x2 matrix.
Definition at line 41 of file geometry.h.
typedef util::Matrix<3,3,double> geometry::Matrix3d |
Type of 3x3 matrix.
Definition at line 46 of file geometry.h.
typedef util::Matrix<4,4,double> geometry::Matrix4d |
Type of a 4x4 matrix.
Definition at line 51 of file geometry.h.
typedef util::Vector<2,double> geometry::Point2d |
Type of a 2D point.
Definition at line 36 of file geometry.h.
typedef util::Vector<3,double> geometry::Point3d |
Type of a 3D point.
Definition at line 31 of file geometry.h.
typedef util::Vector<4,double> geometry::Point4d |
Type of a 4D point.
Definition at line 26 of file geometry.h.
Point3d geometry::barycentricToCartesian | ( | const Point3d & | barycentric, | |
const Point3d & | p1, | |||
const Point3d & | p2, | |||
const Point3d & | p3 | |||
) |
Convert barycentric coordinates to cartesian.
The triangle is defined by p1
, p2
, p3
and the result is such that: result = barycentric[0]*p1 + barycentric[1]*p2 + barycentric[2]*p3
Referenced by algorithms::TriangleSurface::point3d(), and algorithms::TriangleSurface::smoothNormal().
Matrix3d geometry::barycentricToCartesian_matrix | ( | const Point3d & | p1, | |
const Point3d & | p2, | |||
const Point3d & | p3 | |||
) |
Convert cartesian coordinates to barycentric coordinates in a triangle.
This version simply returns the matrix that convert from cartesian to barycentric.
Point3d geometry::cartesianToBarycentric | ( | const Point3d & | pos, | |
const Point3d & | p1, | |||
const Point3d & | p2, | |||
const Point3d & | p3 | |||
) |
Convert cartesian coordinates to barycentric coordinates in a triangle.
The triangle is defined by p1
, p2
, p3
and the result is such that: pos = result[0]*p1 + result[1]*p2 + result[2]*p3
Referenced by algorithms::TriangleSurface::position(), and algorithms::TriangleSurface::vector().
Matrix3d geometry::cartesianToBarycentric_matrix | ( | const Point3d & | p1, | |
const Point3d & | p2, | |||
const Point3d & | p3, | |||
int & | index_one | |||
) |
Convert cartesian coordinates to barycentric coordinates in a triangle.
This version simply returns the matrix that convert from cartesian to barycentric. The resulting matrix has to be used like this:
Point3d pos(x,y,z); int index_one; Matrix3d mat = cartesianToBarycentric_matrix(p1, p2, p3, index_one); pos[index_one] = 1; Point3d bar = mat*pos;
index_one | Index of the position that has to be set to one. |
Point2d geometry::centroid | ( | const std::vector< Point2d > & | polygon | ) |
Center of mass of a 2D non-overlapping polygon.
bool geometry::lineLineIntersection | ( | Point2d & | u, | |
const Point2d & | p1, | |||
const Point2d & | u1, | |||
const Point2d & | p2, | |||
const Point2d & | u2 | |||
) |
Find if the segment [p1,p2] intersect the line going through p of normal n.
[out] | u | Intersection point if the function returns true, untouched otherwise |
[in] | p1 | Point on the first line |
[in] | u1 | Vector along the first line |
[in] | p2 | Point on the second line |
[in] | u2 | Vector along the second line |
bool geometry::lineSegmentIntersection | ( | Point2d & | u, | |
const Point2d & | p1, | |||
const Point2d & | p2, | |||
const Point2d & | p, | |||
const Point2d & | n | |||
) |
Find if the segment [p1,p2] intersect the line going through p of normal n.
[out] | u | Intersection point if the function returns true, untouched otherwise |
[in] | p1 | First point of the segment |
[in] | p2 | Second point of the segment |
[in] | p | Point on the line |
[in] | n | Normal vector to the line |
bool geometry::lineTriangleIntersection | ( | Point3d & | u, | |
double & | s, | |||
const Point3d & | p1, | |||
const Point3d & | p2, | |||
const Point3d & | tr1, | |||
const Point3d & | tr2, | |||
const Point3d & | tr3 | |||
) |
Line-triangle intersection.
[out] | u | Intersection point if any |
[out] | s | Position of the intersection on the line. Between 0 and 1, the intersection is on the segment. Greater than 0, the position is on the ray starting on u1 and going through u2 . If the line doesn't intersect the plane, s is valued to NaN. |
[in] | p1 | Starting point of the segment |
[in] | p2 | Ending point of the segment |
[in] | tr1 | First triangle point |
[in] | tr2 | Second triangle point |
[in] | tr3 | Third triangle point |
bool geometry::planeLineIntersection | ( | Point3d & | u, | |
double & | s, | |||
const Point3d & | p, | |||
const Point3d & | n, | |||
const Point3d & | u1, | |||
const Point3d & | u2 | |||
) |
Plane-Line Intersection.
This function compute the intersection of the line [u1,u2]
and the plane defined by the point p
and the normal n
.
[out] | u | Intersection point if any |
[out] | s | Position of the intersection on the line. Between 0 and 1, the intersection is on the segment. Greater than 0, the position is on the ray starting on u1 and going through u2 . |
[in] | p | Point contained in the plane |
[in] | n | Normal of the plane |
[in] | u1 | Starting point of the segment |
[in] | u2 | Ending point of the segment |
Referenced by tissue::findDivisionPoints(), cell_system::findDivisionPoints(), and vvcomplex::FindOppositeWall().
bool geometry::pointInPolygon | ( | const Point2d & | p, | |
const std::vector< Point2d > & | polygon | |||
) |
Find if the point p is inside the polygon using the winding number.
bool geometry::pointInTriangle | ( | Point3d & | u, | |
double & | s, | |||
const Point3d & | p, | |||
const Point3d & | p1, | |||
const Point3d & | p2, | |||
const Point3d & | p3 | |||
) |
Point in triangle test (3D).
u | modified to the projection of the point in the triangle plane and | |
s | the square distance from the point to the plane. | |
p | Point to test | |
p1 | First point of the triangle | |
p2 | Second point of the triangle | |
p3 | Third point of the triangle |
Test if the point p
is projected in the triangle (p1
,p2
,p3
).
bool geometry::pointInTriangle | ( | const Point2d & | p, | |
const Point2d & | p1, | |||
const Point2d & | p2, | |||
const Point2d & | p3 | |||
) |
Point in triangle test (2D).
Test if the point p
is in the triangle (p1
,p2
,p3
)
double geometry::polygonArea | ( | const std::vector< util::Vector< N, double > > & | polygon | ) | [inline] |
Area of a planar polygon.
Definition at line 29 of file area.h.
00030 { 00031 size_t k = polygon.size(), h, l, i; 00032 typename util::CrossProductType<N,double>::type surface = 0; 00033 if(polygon.empty()) 00034 return 0; 00035 h = (k-1)/2; 00036 if(k%2) 00037 l = 0; 00038 else 00039 l = k-1; 00040 for(i = 1 ; i < h ; i++) 00041 surface += (polygon[2*i] - polygon[0]) ^ (polygon[2*i+1] - polygon[2*i-1]); 00042 surface += (polygon[2*h] - polygon[0]) ^ (polygon[l] - polygon[2*h-1]); 00043 surface /= 2; 00044 return util::norm(surface); 00045 }
util::Vector<N,double> geometry::projectPointOnLine | ( | const util::Vector< N, double > & | pt, | |
const util::Vector< N, double > & | u1, | |||
const util::Vector< N, double > & | u2, | |||
bool | strict = false | |||
) | [inline] |
Project a point on a line.
pt | Point to project | |
u1 | Start of the line | |
u2 | End of the line | |
strict | If true, only the segment is considered, otherwise the whole line is |
Definition at line 29 of file projection.h.
00030 { 00031 util::Vector<N,double> u = u2-u1; 00032 util::Vector<N,double> pv = pt-u1; 00033 double l = util::norm(u); 00034 u /= l; 00035 double proj_val = pv*u; 00036 if(strict) 00037 { 00038 if(proj_val < 0) 00039 proj_val = 0; 00040 else if(proj_val > l) 00041 proj_val = l; 00042 } 00043 return u1 + u*proj_val; 00044 }
Point3d geometry::projectPointOnPlane | ( | const Point3d & | pos, | |
const Point3d & | p, | |||
const Point3d & | n | |||
) | [inline] |
Project a point into a plane defined by a point and a normal to the plane.
pos | Point to project | |
p | Point of the plane | |
n | Normal to the plane |
Definition at line 67 of file projection.h.
00068 { 00069 Point3d res = pos - ((pos-p)*n)*n; 00070 return res; 00071 }
Point3d geometry::projectPointOnTriangle | ( | const Point3d & | pt, | |
const Point3d & | p1, | |||
const Point3d & | p2, | |||
const Point3d & | p3, | |||
double & | s, | |||
bool * | in_triangle = 0 | |||
) |
Project a point into a triangle.
pt | Point to project | |
p1 | First point of the triangle | |
p2 | Second point of the triangle | |
p3 | Third point of the triangle | |
s | Square of the distance from the triangle to the point | |
in_triangle | If not null, set to true if the orthogonal projection is in the triangle, false otherwise. |
pt
. Referenced by algorithms::TriangleSurface::position().
bool geometry::segmentSegmentIntersection | ( | Point2d & | u, | |
const Point2d & | p1, | |||
const Point2d & | p2, | |||
const Point2d & | q1, | |||
const Point2d & | q2 | |||
) |
Find if two 2D segments intersect.
Based on "Faster line segment intersection." Graphics Gems III.
u | The actual intersection point, if any. |
double geometry::triangleArea | ( | const util::Vector< N, double > & | a, | |
const util::Vector< N, double > & | b, | |||
const util::Vector< N, double > & | c | |||
) | [inline] |
Area of a triangle in 2D or 3D.
Definition at line 20 of file area.h.
Referenced by vvcomplex::findCenter(), tissue_model::TissueModel< RealModel, TissueClass >::updateCellsArea(), bspline_tissue_model::TissueModel< RealModel, TissueClass >::updateCellsArea(), cell_system::CellSystem< TissueClass, RealModel >::updateCellsArea(), and cell_system::volumeLeftCell().