Go to the documentation of this file.
53 const std::vector<TPolygon3D>& oldPolys,
54 std::vector<TPolygonWithPlane>& newPolys);
69 bool intersect(
const TSegment3D& s1,
const TSegment3D& s2, TObject3D&
obj);
79 bool intersect(
const TSegment3D& s1,
const TPlane& p2, TObject3D&
obj);
89 bool intersect(
const TSegment3D& s1,
const TLine3D& r2, TObject3D&
obj);
110 bool intersect(
const TPlane& p1,
const TPlane& p2, TObject3D&
obj);
120 bool intersect(
const TPlane& p1,
const TLine3D& p2, TObject3D&
obj);
157 bool intersect(
const TLine3D& r1,
const TLine3D& r2, TObject3D&
obj);
168 bool intersect(
const TLine2D& r1,
const TLine2D& r2, TObject2D&
obj);
178 bool intersect(
const TLine2D& r1,
const TSegment2D& s2, TObject2D&
obj);
201 bool intersect(
const TSegment2D& s1,
const TSegment2D& s2, TObject2D&
obj);
213 double getAngle(
const TPlane& p1,
const TPlane& p2);
218 double getAngle(
const TPlane& p1,
const TLine3D& r2);
231 double getAngle(
const TLine3D& r1,
const TLine3D& r2);
236 double getAngle(
const TLine2D& r1,
const TLine2D& r2);
286 const TPose2D&
p,
const double (&vector)[2], TLine2D&
r);
358 TPolygon3D& newPolygon);
362 TObject3D& newObject);
393 std::vector<T>& newObjs)
395 size_t N = objs.size();
397 for (
size_t i = 0; i < N; i++)
project3D(objs[i], newXYpose, newObjs[i]);
402 const TPoint2D& point,
const TPose2D& newXpose, TPoint2D& newPoint);
413 void project2D(
const TLine2D& line,
const TPose2D& newXpose, TLine2D& newLine);
416 const TPolygon2D& polygon,
const TPose2D& newXpose, TPolygon2D& newPolygon);
419 const TObject2D&
object,
const TPose2D& newXpose, TObject2D& newObject);
426 template <
class T,
class CPOSE2D>
439 template <
class T,
class CPOSE2D>
451 const std::vector<T>& objs,
const TPose2D& newXpose,
452 std::vector<T>& newObjs)
454 size_t N = objs.size();
456 for (
size_t i = 0; i < N; i++)
project2D(objs[i], newXpose, newObjs[i]);
467 bool intersect(
const TPolygon2D& p1,
const TSegment2D& s2, TObject2D&
obj);
469 bool intersect(
const TPolygon2D& p1,
const TLine2D& r2, TObject2D&
obj);
471 bool intersect(
const TPolygon2D& p1,
const TPolygon2D& p2, TObject2D&
obj);
486 bool intersect(
const TPolygon3D& p1,
const TSegment3D& s2, TObject3D&
obj);
488 bool intersect(
const TPolygon3D& p1,
const TLine3D& r2, TObject3D&
obj);
490 bool intersect(
const TPolygon3D& p1,
const TPlane& p2, TObject3D&
obj);
492 bool intersect(
const TPolygon3D& p1,
const TPolygon3D& p2, TObject3D&
obj);
516 const std::vector<TPolygon3D>&
v1,
const std::vector<TPolygon3D>&
v2,
517 CSparseMatrixTemplate<TObject3D>& objs);
523 const std::vector<TPolygon3D>&
v1,
const std::vector<TPolygon3D>&
v2,
524 std::vector<TObject3D>& objs);
534 template <
class T,
class U,
class O>
536 const std::vector<T>&
v1,
const std::vector<U>&
v2,
539 size_t M =
v1.size(), N =
v2.size();
543 for (
size_t i = 0; i < M; i++)
544 for (
size_t j = 0; j < M; j++)
552 template <
class T,
class U,
class O>
554 const std::vector<T>&
v1,
const std::vector<U>&
v2, std::vector<O> objs)
559 it1 !=
v1.end(); ++it1)
561 const T& elem1 = *it1;
563 it2 !=
v2.end(); ++it2)
570 bool intersect(
const TObject2D& o1,
const TObject2D& o2, TObject2D&
obj);
572 bool intersect(
const TObject3D& o1,
const TObject3D& o2, TObject3D&
obj);
580 double distance(
const TPoint2D& p1,
const TPoint2D& p2);
582 double distance(
const TPoint3D& p1,
const TPoint3D& p2);
584 double distance(
const TLine2D& r1,
const TLine2D& r2);
586 double distance(
const TLine3D& r1,
const TLine3D& r2);
589 double distance(
const TPlane& p1,
const TPlane& p2);
591 double distance(
const TPolygon2D& p1,
const TPolygon2D& p2);
593 double distance(
const TPolygon2D& p1,
const TSegment2D& s2);
600 double distance(
const TPolygon2D& p1,
const TLine2D& l2);
606 double distance(
const TPolygon3D& p1,
const TPolygon3D& p2);
608 double distance(
const TPolygon3D& p1,
const TSegment3D& s2);
615 double distance(
const TPolygon3D& p1,
const TLine3D& l2);
622 double distance(
const TPolygon3D& po,
const TPlane& pl);
636 const std::vector<TPoint2D>& poly, TPoint2D& pMin, TPoint2D& pMax);
639 const std::vector<TPoint3D>& poly, TPoint3D& pMin, TPoint3D& pMax);
710 const std::vector<TSegment3D>& segms, std::vector<TPolygon3D>& polys);
716 const std::vector<TSegment3D>& segms, std::vector<TPolygon3D>& polys,
717 std::vector<TSegment3D>& remainder);
723 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys);
729 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
730 std::vector<TObject3D>& remainder);
736 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
737 std::vector<TSegment3D>& remainder1, std::vector<TObject3D>& remainder2);
753 const TPolygon2D& poly, std::vector<TPolygon2D>&
components);
759 const TPolygon3D& poly, std::vector<TPolygon3D>&
components);
796 std::vector<TPolygonWithPlane> pwp;
813 template <
class T,
class U,
class V>
816 vOut[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
817 vOut[1] =
v0[2] *
v1[0] -
v0[0] *
v1[2];
818 vOut[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
824 const std::vector<T>&
v0,
const std::vector<T>&
v1, std::vector<T>& v_out)
829 v_out[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
830 v_out[1] = -
v0[0] *
v1[2] +
v0[2] *
v1[0];
831 v_out[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
835 template <
class VEC1,
class VEC2>
837 const VEC1&
v0,
const VEC2&
v1)
839 Eigen::Matrix<double, 3, 1> vOut;
840 vOut[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
841 vOut[1] =
v0[2] *
v1[0] -
v0[0] *
v1[2];
842 vOut[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
855 template <
class VECTOR,
class MATRIX>
860 M.set_unsafe(0, 0, 0);
861 M.set_unsafe(0, 1, -
v[2]);
862 M.set_unsafe(0, 2,
v[1]);
863 M.set_unsafe(1, 0,
v[2]);
864 M.set_unsafe(1, 1, 0);
865 M.set_unsafe(1, 2, -
v[0]);
866 M.set_unsafe(2, 0, -
v[1]);
867 M.set_unsafe(2, 1,
v[0]);
868 M.set_unsafe(2, 2, 0);
871 template <
class VECTOR>
889 template <
class VECTOR,
class MATRIX>
894 M.set_unsafe(0, 0, 0);
895 M.set_unsafe(0, 1,
v[2]);
896 M.set_unsafe(0, 2, -
v[1]);
897 M.set_unsafe(1, 0, -
v[2]);
898 M.set_unsafe(1, 1, 0);
899 M.set_unsafe(1, 2,
v[0]);
900 M.set_unsafe(2, 0,
v[1]);
901 M.set_unsafe(2, 1, -
v[0]);
902 M.set_unsafe(2, 2, 0);
905 template <
class VECTOR>
917 template <
class T,
class U>
927 template <
class T,
class U>
939 const double& Px,
const double& Py,
const double& x1,
const double& y1,
940 const double& x2,
const double& y2,
double& out_x,
double& out_y);
946 const double& Px,
const double& Py,
const double& x1,
const double& y1,
947 const double& x2,
const double& y2,
double& out_x,
double& out_y);
952 const double& Px,
const double& Py,
const double& x1,
const double& y1,
953 const double& x2,
const double& y2);
956 template <
typename T>
963 template <
typename T>
965 const T x1,
const T y1,
const T z1,
const T x2,
const T y2,
const T z2)
971 template <
typename T>
978 template <
typename T>
980 const T x1,
const T y1,
const T z1,
const T x2,
const T y2,
const T z2)
988 template <
typename T>
990 const double Px,
const double Py,
const double x1,
const double y1,
991 const double x2,
const double y2, T& out_x, T& out_y)
995 out_x =
static_cast<T
>(ox);
996 out_y =
static_cast<T
>(oy);
1003 const double x1,
const double y1,
const double x2,
const double y2,
1004 const double x3,
const double y3,
const double x4,
const double y4,
1005 double& ix,
double& iy);
1010 const double x1,
const double y1,
const double x2,
const double y2,
1011 const double x3,
const double y3,
const double x4,
const double y4,
1012 float& ix,
float& iy);
1018 const double& px,
const double& py,
unsigned int polyEdges,
1019 const double* poly_xs,
const double* poly_ys);
1024 template <
typename T>
1026 T
x, T
y, T v1x, T v1y, T v2x, T v2y, T v3x, T v3y, T v4x, T v4y)
1030 const T
a1 = atan2(v1y -
y, v1x -
x);
1031 const T
a2 = atan2(v2y -
y, v2x -
x);
1032 const T
a3 = atan2(v3y -
y, v3x -
x);
1033 const T a4 = atan2(v4y -
y, v4x -
x);
1039 if (
sign(da1) !=
sign(da2))
return false;
1042 if (
sign(da2) !=
sign(da3))
return false;
1052 const double& px,
const double& py,
unsigned int polyEdges,
1053 const double* poly_xs,
const double* poly_ys);
1065 const double& p1_x,
const double& p1_y,
const double& p1_z,
1066 const double& p2_x,
const double& p2_y,
const double& p2_z,
1067 const double& p3_x,
const double& p3_y,
const double& p3_z,
1068 const double& p4_x,
const double& p4_y,
const double& p4_z,
double&
x,
1069 double&
y,
double&
z,
double& dist);
1081 const double& R1_x_min,
const double& R1_x_max,
const double& R1_y_min,
1082 const double& R1_y_max,
const double& R2_x_min,
const double& R2_x_max,
1083 const double& R2_y_min,
const double& R2_y_max,
const double& R2_pose_x,
1084 const double& R2_pose_y,
const double& R2_pose_phi);
1128 if (dx == 0 && dy == 0 && dz == 0)
1135 T
n = sqrt(n_xy +
square(dz));
1142 if (fabs(dx) > 1e-4 || fabs(dy) > 1e-4)
1144 P(0, 1) = -dy / n_xy;
1145 P(1, 1) = dx / n_xy;
void skew_symmetric3_neg(const VECTOR &v, MATRIX &M)
Computes the negative version of a 3x3 skew symmetric matrix from a 3-vector or 3-array:
bool pointIntoQuadrangle(T x, T y, T v1x, T v1y, T v2x, T v2y, T v3x, T v3y, T v4x, T v4y)
Specialized method to check whether a point (x,y) falls into a quadrangle.
void createFromPoseX(const mrpt::math::TPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the X axis in a given pose.
void createPlaneFromPoseYZ(const mrpt::math::TPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its X vector.
const Scalar * const_iterator
bool areAligned(const std::vector< TPoint2D > &points)
Checks whether this set of points acceptably fits a 2D line.
void getRectangleBounds(const std::vector< TPoint2D > &poly, TPoint2D &pMin, TPoint2D &pMax)
Gets the rectangular bounds of a 2D polygon or set of 2D points.
void createPlaneFromPoseXZ(const mrpt::math::TPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Y vector.
void project2D(const TPoint2D &point, const TPose2D &newXpose, TPoint2D &newPoint)
Uses the given pose 2D to project a point into a new base.
void composePoint(const TPoint3D l, TPoint3D &g) const
void createFromPoseZ(const mrpt::math::TPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Z axis in a given pose.
Slightly heavyweight type to speed-up calculations with polygons in 3D.
GLsizei const GLfloat * points
GLsizei GLsizei GLuint * obj
double getRegressionPlane(const std::vector< TPoint3D > &points, TPlane &plane)
Using eigenvalues, gets the best fitting plane for a set of 3D points.
void project3D(const TPoint3D &point, const mrpt::math::TPose3D &newXYpose, TPoint3D &newPoint)
Uses the given pose 3D to project a point into a new base.
Standard type for storing any lightweight 2D type.
Standard object for storing any 3D lightweight object.
CMatrixTemplateNumeric< T > generateAxisBaseFromDirection(T dx, T dy, T dz)
Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of the...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
#define THROW_EXCEPTION(msg)
#define ASSERT_(f)
Defines an assertion mechanism.
T square(const T x)
Inline function for the square of a number.
void getPrismBounds(const std::vector< TPoint3D > &poly, TPoint3D &pMin, TPoint3D &pMax)
Gets the prism bounds of a 3D polygon or set of 3D points.
void closestFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a (infinite) line.
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
bool minDistBetweenLines(const double &p1_x, const double &p1_y, const double &p1_z, const double &p2_x, const double &p2_y, const double &p2_z, const double &p3_x, const double &p3_y, const double &p3_z, const double &p4_x, const double &p4_y, const double &p4_z, double &x, double &y, double &z, double &dist)
Calculates the minimum distance between a pair of lines.
TPoint3D point1
Origin point.
bool pointIntoPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns true if the 2D point (px,py) falls INTO the given polygon.
A matrix of dynamic size.
GLdouble GLdouble GLdouble r
void createFromPoseAndVector(const mrpt::math::TPose3D &p, const double(&vector)[3], TLine3D &r)
Gets a 3D line corresponding to any arbitrary vector, in the base given by the pose.
TPoint3D point2
Destiny point.
void createPlaneFromPoseXY(const mrpt::math::TPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Z vector.
T distanceSqrBetweenPoints(const T x1, const T y1, const T x2, const T y2)
Returns the square distance between 2 points in 2D.
size_t getNonNullElements() const
Gets the amount of non-null elements inside the matrix.
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
TPolygonWithPlane()
Basic constructor.
GLfloat GLfloat GLfloat v2
TPolygon3D poly
Actual polygon.
void createPlaneFromPoseAndNormal(const mrpt::math::TPose3D &pose, const double(&normal)[3], TPlane &plane)
Given a pose and any vector, creates a plane orthogonal to that vector in the pose's coordinates.
double minimumDistanceFromPointToSegment(const double Px, const double Py, const double x1, const double y1, const double x2, const double y2, T &out_x, T &out_y)
Computes the closest point from a given point to a segment, and returns that minimum distance.
void getAngleBisector(const TLine2D &l1, const TLine2D &l2, TLine2D &bis)
Gets the bisector of two lines or segments (implicit constructor will be used if necessary)
T distanceBetweenPoints(const T x1, const T y1, const T x2, const T y2)
Returns the distance between 2 points in 2D.
void getAsPose3D(mrpt::math::TPose3D &outPose)
A sparse matrix container (with cells of any type), with iterators.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
bool conformAPlane(const std::vector< TPoint3D > &points)
Checks whether this polygon or set of points acceptably fits a plane.
void resize(size_t nRows, size_t nCols)
Changes the size of the matrix.
2D polygon, inheriting from std::vector<TPoint2D>.
2D segment, consisting of two points.
3D polygon, inheriting from std::vector<TPoint3D>
bool vectorsAreParallel3D(const T &v1, const U &v2)
Returns true if two 3D vectors are parallel.
3D segment, consisting of two points.
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
static void getPlanes(const std::vector< TPolygon3D > &oldPolys, std::vector< TPolygonWithPlane > &newPolys)
Static method for vectors.
GLenum GLenum GLuint components
TPlane plane
Plane containing the polygon.
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
3D Plane, represented by its equation
bool RectanglesIntersection(const double &R1_x_min, const double &R1_x_max, const double &R1_y_min, const double &R1_y_max, const double &R2_x_min, const double &R2_x_max, const double &R2_y_min, const double &R2_y_max, const double &R2_pose_x, const double &R2_pose_y, const double &R2_pose_phi)
Returns whether two rotated rectangles intersect.
void generateAxisBaseFromDirectionAndAxis(const double(&vec)[3], char coord, CMatrixDouble44 &matrix)
Creates a homogeneus matrix (4x4) such that the coordinate given (0 for x, 1 for y,...
CMatrixFixedNumeric< double, 4, 4 > CMatrixDouble44
TPolygon2D poly2D
Polygon, after being projected to the plane using inversePose.
void clear()
Completely removes all elements, although maintaining the matrix's size.
void closestFromPointToSegment(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a segment.
void skew_symmetric3(const VECTOR &v, MATRIX &M)
Computes the 3x3 skew symmetric matrix from a 3-vector or 3-array:
double distancePointToPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns the closest distance of a given 2D point to a polygon, or "0" if the point is INTO the polygo...
void getAsPose2D(TPose2D &outPose) const
double getAngle(const TPlane &p1, const TPlane &p2)
Computes the angle between two planes.
bool splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
mrpt::math::TPose3D pose
Plane's pose.
2D line without bounds, represented by its equation .
3D line, represented by a base point and a director vector.
void setEpsilon(double nE)
Changes the value of the geometric epsilon (default = 1e-5)
void getAsPose2DForcingOrigin(const TPoint2D &origin, TPose2D &outPose) const
bool SegmentsIntersection(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, const double x4, const double y4, double &ix, double &iy)
Returns the intersection point, and if it exists, between two segments.
double closestSquareDistanceFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2)
Returns the square distance from a point to a line.
TPoint2D point1
Origin point.
void assemblePolygons(const std::vector< TSegment3D > &segms, std::vector< TPolygon3D > &polys)
Tries to assemble a set of segments into a set of closed polygons.
void getSegmentBisector(const TSegment2D &sgm, TLine2D &bis)
Gets the bisector of a 2D segment.
TPoint2D point2
Destiny point.
int sign(T x)
Returns the sign of X as "1" or "-1".
bool vectorsAreParallel2D(const T &v1, const U &v2)
Returns true if two 2D vectors are parallel.
mrpt::math::TPose3D inversePose
Plane's inverse pose.
double getRegressionLine(const std::vector< TPoint2D > &points, TLine2D &line)
Using eigenvalues, gets the best fitting line for a set of 2D points.
void createFromPoseY(const mrpt::math::TPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Y axis in a given pose.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at mié 12 jul 2023 10:03:34 CEST | |