37 #include <Eigen/Dense> 47 static_assert(std::is_trivial_v<TPoint2D_data>);
48 static_assert(std::is_trivially_copyable_v<TPoint2D>);
49 static_assert(std::is_trivial_v<TPoint3D_data>);
50 static_assert(std::is_trivially_copyable_v<TPoint3D>);
51 static_assert(std::is_trivially_copyable_v<TPose2D>);
52 static_assert(std::is_trivially_copyable_v<TPose3D>);
53 static_assert(std::is_trivially_copyable_v<TPlane3D>);
54 static_assert(std::is_trivially_copyable_v<TLine2D>);
55 static_assert(std::is_trivially_copyable_v<TLine3D>);
56 static_assert(std::is_trivially_copyable_v<TTwist2D>);
57 static_assert(std::is_trivially_copyable_v<TTwist3D>);
90 m.
rows() == 1 && m.
cols() == 2,
"Wrong size of vector in ::fromString");
108 m.
rows() == 1 && m.
cols() == 3,
"Wrong size of vector in ::fromString");
116 const double A_cosphi = cos(this->phi), A_sinphi = sin(this->phi);
118 const double new_x = this->
x +
b.x * A_cosphi -
b.y * A_sinphi;
119 const double new_y = this->
y +
b.x * A_sinphi +
b.y * A_cosphi;
128 const double B_cosphi = cos(
b.phi), B_sinphi = sin(
b.phi);
131 (this->
x -
b.x) * B_cosphi + (this->
y -
b.y) * B_sinphi;
133 -(this->
x -
b.x) * B_sinphi + (this->
y -
b.y) * B_cosphi;
140 const double ccos = ::cos(
phi), csin = ::sin(
phi);
141 return {
x + l.
x * ccos - l.
y * csin,
y + l.
x * csin + l.
y * ccos};
150 const double Ax =
g.
x -
x, Ay =
g.y -
y, ccos = ::cos(
phi),
152 return {Ax * ccos + Ay * csin, -Ax * csin + Ay * ccos};
166 m.
rows() == 1 && m.
cols() == 3,
"Wrong size of vector in ::fromString");
175 const double nvx =
vx * cos(ang) -
vy * sin(ang);
176 const double nvy =
vx * sin(ang) +
vy * cos(ang);
203 m.
rows() == 1 && m.
cols() == 6,
"Wrong size of vector in ::fromString");
204 for (
int i = 0; i < 3; i++) (*
this)[i] = m(0, i);
205 for (
int i = 0; i < 3; i++) (*
this)[3 + i] =
DEG2RAD(m(0, 3 + i));
215 vx =
R(0, 0) *
t.vx +
R(0, 1) *
t.vy +
R(0, 2) *
t.vz;
216 vy =
R(1, 0) *
t.vx +
R(1, 1) *
t.vy +
R(1, 2) *
t.vz;
217 vz =
R(2, 0) *
t.vx +
R(2, 1) *
t.vy +
R(2, 2) *
t.vz;
219 wx =
R(0, 0) *
t.wx +
R(0, 1) *
t.wy +
R(0, 2) *
t.wz;
220 wy =
R(1, 0) *
t.wx +
R(1, 1) *
t.wy +
R(1, 2) *
t.wz;
221 wz =
R(2, 0) *
t.wx +
R(2, 1) *
t.wy +
R(2, 2) *
t.wz;
266 m.
rows() == 1 && m.
cols() == 3,
"Wrong size of vector in ::fromString");
296 const double cy = cos(
yaw * 0.5), sy = sin(
yaw * 0.5);
297 const double cp = cos(
pitch * 0.5), sp = sin(
pitch * 0.5);
298 const double cr = cos(
roll * 0.5), sr = sin(
roll * 0.5);
300 const double ccc = cr * cp * cy;
301 const double ccs = cr * cp * sy;
302 const double css = cr * sp * sy;
303 const double sss = sr * sp * sy;
304 const double scc = sr * cp * cy;
305 const double ssc = sr * sp * cy;
306 const double csc = cr * sp * cy;
307 const double scs = sr * cp * sy;
320 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[4 * 3] = {
321 -0.5 *
q[3], 0.5 * (-csc + scs), -0.5 *
q[1],
322 -0.5 *
q[2], 0.5 * (-ssc - ccs), 0.5 *
q[0],
323 0.5 *
q[1], 0.5 * (ccc - sss), 0.5 *
q[3],
324 0.5 *
q[0], 0.5 * (-css - scc), -0.5 *
q[2]};
333 res.x =
R(0, 0) * l.
x +
R(0, 1) * l.
y +
R(0, 2) * l.
z + this->
x;
334 res.
y =
R(1, 0) * l.
x +
R(1, 1) * l.
y +
R(1, 2) * l.
z + this->
y;
335 res.
z =
R(2, 0) * l.
x +
R(2, 1) * l.
y +
R(2, 2) * l.
z + this->
z;
351 res.x = H(0, 0) *
g.x + H(0, 1) *
g.y + H(0, 2) *
g.z + H(0, 3);
352 res.y = H(1, 0) *
g.x + H(1, 1) *
g.y + H(1, 2) *
g.z + H(1, 3);
353 res.z = H(2, 0) *
g.x + H(2, 1) *
g.y + H(2, 2) *
g.z + H(2, 3);
366 const double cy = cos(
yaw);
367 const double sy = sin(
yaw);
368 const double cp = cos(
pitch);
369 const double sp = sin(
pitch);
370 const double cr = cos(
roll);
371 const double sr = sin(
roll);
373 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
374 const double rot_vals[] = {cy * cp,
375 cy * sp * sr - sy * cr,
376 cy * sp * cr + sy * sr,
378 sy * sp * sr + cy * cr,
379 sy * sp * cr - cy * sr,
383 R.loadFromArray(rot_vals);
393 "Homogeneous matrix is not orthogonal & normalized!: " +
399 "Homogeneous matrix is not orthogonal & normalized!: " +
405 "Homogeneous matrix is not orthogonal & normalized!: " +
409 pitch = atan2(-
R(2, 0), hypot(
R(0, 0),
R(1, 0)));
412 if ((fabs(
R(2, 1)) + fabs(
R(2, 2))) <
413 10 * std::numeric_limits<double>::epsilon())
437 yaw = atan2(
R(1, 2),
R(0, 2));
439 yaw = atan2(-
R(1, 2), -
R(0, 2));
443 roll = atan2(
R(2, 1),
R(2, 2));
445 yaw = atan2(
R(1, 0),
R(0, 0));
469 HG.
block<3, 3>(0, 0) =
R.asEigen();
473 HG(3, 0) = HG(3, 1) = HG(3, 2) = 0.;
488 m.
rows() == 1 && m.
cols() == 6,
"Wrong size of vector in ::fromString");
503 m.
rows() == 1 && m.
cols() == 7,
"Wrong size of vector in ::fromString");
504 for (
int i = 0; i < m.
cols(); i++) (*
this)[i] = m(0, i);
509 p.getInverseHomogeneousMatrix(H);
518 a.getInverseHomogeneousMatrix(Hainv);
519 b.getHomogeneousMatrix(Hb);
528 return (o <<
p.asString());
532 return (o <<
p.asString());
536 return (o <<
p.asString());
540 return (o <<
p.asString());
544 return (o <<
p.asString());
549 return in >>
s.point1 >>
s.point2;
553 return out <<
s.point1 <<
s.point2;
566 return in >>
s.point1 >>
s.point2;
570 return out <<
s.point1 <<
s.point2;
582 return in >>
p.coefs[0] >>
p.coefs[1] >>
p.coefs[2] >>
p.coefs[3];
586 return out <<
p.coefs[0] <<
p.coefs[1] <<
p.coefs[2] <<
p.coefs[3];
605 const double d3 =
length();
606 const double ds1 =
square(d1);
607 const double ds2 =
square(d2);
608 const double ds3 =
square(d3);
609 if (ds1 > (ds2 + ds3) || ds2 > (ds1 + ds3))
630 throw std::logic_error(
"Segment is normal to projection plane");
657 Eigen::Vector3d u,
v,
w;
669 double D =
a *
c -
b *
b;
670 double sc, sN, sD = D;
671 double tc, tN, tD = D;
683 sN = (
b * e -
c * d);
684 tN = (
a * e -
b * d);
719 else if ((-d +
b) >
a)
728 sc = (fabs(sN) < 0.00000001 ? 0.0 : sN / sD);
729 tc = (fabs(tN) < 0.00000001 ? 0.0 : tN / tD);
732 const auto dP = (
w + (sc * u) - (
tc *
v)).eval();
772 vector[0] =
coefs[0];
773 vector[1] =
coefs[1];
778 for (
double& coef :
coefs) coef /=
s;
782 vector[0] = -
coefs[1];
783 vector[1] =
coefs[0];
807 throw std::logic_error(
"Base point is not contained in the line");
814 if (p1 == p2)
throw logic_error(
"Both points are the same");
821 coefs[0] =
s.point2.y -
s.point1.y;
822 coefs[1] =
s.point1.x -
s.point2.x;
823 coefs[2] =
s.point2.x *
s.point1.y -
s.point2.y *
s.point1.x;
830 throw std::logic_error(
"Line is normal to projection plane");
860 double dv = 0, d2 = 0,
v2 = 0;
861 for (
size_t i = 0; i < 3; i++)
867 return sqrt(d2 - (dv * dv) /
v2);
871 double s = sqrt(squareNorm<3, double>(
director));
877 throw logic_error(
"Both points are the same");
912 return dotProduct<3, double>(
coefs, point) +
coefs[3];
937 for (
int i = 0; i < 3; i++) vector[i] =
coefs[i];
942 for (
int i = 0; i < 3; i++)
v[i] =
coefs[i];
948 const double s = sqrt(squareNorm<3, double>(
coefs));
950 const double k = 1.0 /
s;
951 for (
int i = 0; i < 3; i++) vec[i] =
coefs[i] * k;
956 double s = sqrt(squareNorm<3, double>(
coefs));
957 for (
double& coef :
coefs) coef /=
s;
967 for (
size_t i = 0; i < 3; i++)
979 throw std::logic_error(
"Base point is not in the plane.");
984 for (
size_t i = 0; i < 3; i++) AXIS(i, 3) = center[i];
989 double dx1 = p2.
x - p1.
x;
990 double dy1 = p2.
y - p1.
y;
991 double dz1 = p2.
z - p1.
z;
992 double dx2 = p3.
x - p1.
x;
993 double dy2 = p3.
y - p1.
y;
994 double dz2 = p3.
z - p1.
z;
995 coefs[0] = dy1 * dz2 - dy2 * dz1;
996 coefs[1] = dz1 * dx2 - dz2 * dx1;
997 coefs[2] = dx1 * dy2 - dx2 * dy1;
1000 throw logic_error(
"Points are linearly dependent");
1005 double dx1 = p1.
x - r2.
pBase.
x;
1006 double dy1 = p1.
y - r2.
pBase.
y;
1007 double dz1 = p1.
z - r2.
pBase.
z;
1013 throw logic_error(
"Point is contained in the line");
1018 const double normal_norm = normal.
norm();
1022 const auto n = normal * (1. / normal_norm);
1037 if (r1.
contains(r2.
pBase))
throw std::logic_error(
"Lines are the same");
1041 for (
size_t i = 0; i < 3; i++) d[i] = r1.
pBase[i] - r2.
pBase[i];
1047 throw logic_error(
"Lines do not intersect");
1053 size_t N = poly.size();
1055 std::vector<size_t> unused;
1060 unused.push_back(0);
1061 for (
size_t i = 1; i < N - 1; i++)
1066 unused.push_back(i);
1071 unused.push_back(N - 1);
1072 unused.push_back(N);
1074 for (
size_t i = 0; i < unused.size() - 1; i++)
1076 size_t last = unused[i + 1];
1077 for (
size_t j = unused[i] + 1 - diff; j < last - diff; j++)
1078 poly[j] = poly[j + diff];
1080 poly.resize(N + 1 - unused.size());
1085 size_t N = poly.size();
1087 std::vector<size_t> rep;
1088 for (
size_t i = 0; i < N - 1; i++)
1092 rep.push_back(N - 1);
1095 for (
size_t i = 0; i < rep.size() - 1; i++)
1097 size_t last = rep[i + 1];
1098 for (
size_t j = rep[i] + 1 - diff; j < last - diff; j++)
1099 poly[j] = poly[j + diff];
1101 poly.resize(N + 1 - rep.size());
1107 std::vector<TSegment2D> sgs;
1113 double distance = std::numeric_limits<double>::max();
1115 for (
auto it = sgs.begin(); it != sgs.end(); ++it)
1117 double d = (*it).distance(point);
1126 ASSERTMSG_(!this->
empty(),
"getBoundingBox() called on an empty polygon!");
1127 min_coords.
x = min_coords.
y = std::numeric_limits<double>::max();
1128 max_coords.
x = max_coords.
y = -std::numeric_limits<double>::max();
1129 for (
size_t i = 0; i <
size(); i++)
1148 return ((P1.
x - P0.
x) * (P2.
y - P0.
y) - (P2.
x - P0.
x) * (P1.
y - P0.
y));
1156 const size_t n = this->
size();
1157 for (
size_t i = 0; i <
n; i++)
1159 if ((*
this)[i].
y <= P.
y)
1162 if ((*
this)[(i + 1) %
n].
y > P.
y)
1163 if (
isLeft((*
this)[i], (*
this)[(i + 1) %
n], P) >
1170 if ((*
this)[(i + 1) %
n].
y <= P.
y)
1171 if (
isLeft((*
this)[i], (*
this)[(i + 1) %
n], P) <
1183 for (
size_t i = 0; i < N - 1; i++)
1184 v[i] =
TSegment2D(
operator[](i),
operator[](i + 1));
1185 v[N - 1] =
TSegment2D(
operator[](N - 1),
operator[](0));
1193 template <
class T,
int N>
1200 for (
size_t i = 0; i < N; i++)
object[i] = 0.0;
1204 for (
size_t i = 0; i < N; i++)
object[i] += o[i];
1217 if (N <= 3)
return true;
1218 vector<TSegment2D> sgms;
1220 for (
size_t i = 0; i < N; i++)
1224 for (
size_t j = 0; j < N; j++)
1226 double d = l.evaluatePoint(
operator[](j));
1230 s = (d > 0) ? 1 : -1;
1231 else if (
s != ((d > 0) ? 1 : -1))
1244 std::vector<double>&
x, std::vector<double>&
y)
const 1249 for (
size_t i = 0; i < N; i++)
1259 size_t N =
p.
size();
1261 for (
size_t i = 0; i < N; i++)
operator[](i) =
TPoint2D(
p[i]);
1264 size_t numEdges,
double radius,
TPolygon2D& poly)
1266 if (numEdges < 3 || abs(radius) <
getEpsilon())
1267 throw std::logic_error(
1268 "Invalid arguments for regular polygon creations");
1269 poly.resize(numEdges);
1270 for (
size_t i = 0; i < numEdges; i++)
1272 double angle = i *
M_PI * 2 / numEdges;
1273 poly[i] =
TPoint2D(radius * cos(angle), radius * sin(angle));
1280 for (
size_t i = 0; i < numEdges; i++) poly[i] = pose.
composePoint(poly[i]);
1292 throw std::logic_error(
"Polygon does not conform a plane");
1300 return sqrt(newPoint.
z * newPoint.
z + distance2D * distance2D);
1312 throw std::logic_error(
"Polygon does not conform a plane");
1331 for (
size_t i = 0; i < N - 1; i++)
1332 v[i] =
TSegment3D(
operator[](i),
operator[](i + 1));
1333 v[N - 1] =
TSegment3D(
operator[](N - 1),
operator[](0));
1357 size_t N =
p.
size();
1359 for (
size_t i = 0; i < N; i++)
operator[](i) =
p[i];
1362 size_t numEdges,
double radius,
TPolygon3D& poly)
1364 if (numEdges < 3 || abs(radius) <
getEpsilon())
1365 throw std::logic_error(
1366 "Invalid arguments for regular polygon creations");
1367 poly.resize(numEdges);
1368 for (
size_t i = 0; i < numEdges; i++)
1370 double angle = i * 2 *
M_PI / numEdges;
1371 poly[i] =
TPoint3D(radius * cos(angle), radius * sin(angle), 0);
1378 for (
size_t i = 0; i < numEdges; i++) pose.
composePoint(poly[i], poly[i]);
1403 const std::vector<TObject2D>& objs, std::vector<TPoint2D>& pnts)
1405 for (
const auto&
obj : objs)
1406 if (
obj.isPoint()) pnts.push_back(
obj.data.point);
1409 const std::vector<TObject2D>& objs, std::vector<TSegment2D>& sgms)
1411 for (
const auto&
obj : objs)
1412 if (
obj.isSegment()) sgms.push_back(
obj.data.segment);
1415 const std::vector<TObject2D>& objs, std::vector<TLine2D>& lins)
1417 for (
const auto&
obj : objs)
1418 if (
obj.isLine()) lins.push_back(
obj.data.line);
1421 const std::vector<TObject2D>& objs, std::vector<TPolygon2D>& polys)
1423 for (
const auto&
obj : objs)
1424 if (
obj.isPolygon()) polys.push_back(*(
obj.data.polygon));
1427 const std::vector<TObject2D>& objs, std::vector<TPoint2D>& pnts,
1428 std::vector<TObject2D>& remainder)
1430 for (
const auto&
obj : objs)
1432 pnts.push_back(
obj.data.point);
1434 remainder.push_back(
obj);
1437 const std::vector<TObject2D>& objs, std::vector<TSegment2D>& sgms,
1438 std::vector<TObject2D>& remainder)
1440 for (
const auto&
obj : objs)
1441 if (
obj.isSegment())
1442 sgms.push_back(
obj.data.segment);
1444 remainder.push_back(
obj);
1447 const std::vector<TObject2D>& objs, std::vector<TLine2D>& lins,
1448 std::vector<TObject2D>& remainder)
1450 for (
const auto&
obj : objs)
1452 lins.push_back(
obj.data.line);
1454 remainder.push_back(
obj);
1457 const std::vector<TObject2D>& objs, std::vector<TPolygon2D>& polys,
1458 vector<TObject2D>& remainder)
1460 for (
const auto&
obj : objs)
1461 if (
obj.isPolygon())
1462 polys.push_back(*(
obj.data.polygon));
1464 remainder.push_back(
obj);
1484 throw std::logic_error(
"Too many dimensions");
1492 const std::vector<TObject3D>& objs, std::vector<TPoint3D>& pnts)
1494 for (
const auto&
obj : objs)
1495 if (
obj.isPoint()) pnts.push_back(
obj.data.point);
1498 const std::vector<TObject3D>& objs, std::vector<TSegment3D>& sgms)
1500 for (
const auto&
obj : objs)
1501 if (
obj.isSegment()) sgms.push_back(
obj.data.segment);
1504 const std::vector<TObject3D>& objs, std::vector<TLine3D>& lins)
1506 for (
const auto&
obj : objs)
1507 if (
obj.isLine()) lins.push_back(
obj.data.line);
1510 const std::vector<TObject3D>& objs, std::vector<TPlane>& plns)
1512 for (
const auto&
obj : objs)
1513 if (
obj.isPlane()) plns.push_back(
obj.data.plane);
1516 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys)
1518 for (
const auto&
obj : objs)
1519 if (
obj.isPolygon()) polys.push_back(*(
obj.data.polygon));
1522 const std::vector<TObject3D>& objs, std::vector<TPoint3D>& pnts,
1523 std::vector<TObject3D>& remainder)
1525 for (
const auto&
obj : objs)
1527 pnts.push_back(
obj.data.point);
1529 remainder.push_back(
obj);
1532 const std::vector<TObject3D>& objs, std::vector<TSegment3D>& sgms,
1533 std::vector<TObject3D>& remainder)
1535 for (
const auto&
obj : objs)
1536 if (
obj.isSegment())
1537 sgms.push_back(
obj.data.segment);
1539 remainder.push_back(
obj);
1542 const std::vector<TObject3D>& objs, std::vector<TLine3D>& lins,
1543 std::vector<TObject3D>& remainder)
1545 for (
const auto&
obj : objs)
1547 lins.push_back(
obj.data.line);
1549 remainder.push_back(
obj);
1552 const std::vector<TObject3D>& objs, std::vector<TPlane>& plns,
1553 std::vector<TObject3D>& remainder)
1555 for (
const auto&
obj : objs)
1557 plns.push_back(
obj.data.plane);
1559 remainder.push_back(
obj);
1562 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
1563 vector<TObject3D>& remainder)
1565 for (
const auto&
obj : objs)
1566 if (
obj.isPolygon())
1567 polys.push_back(*(
obj.data.polygon));
1569 remainder.push_back(
obj);
1574 for (
unsigned int i = 0; i < o.
size(); i++)
in >> o[i];
1579 for (
unsigned int i = 0; i < o.
size(); i++) out << o[i];
1585 for (
unsigned int i = 0; i < o.
size(); i++)
in >> o[i];
1590 for (
unsigned int i = 0; i < o.
size(); i++) out << o[i];
1598 switch (static_cast<unsigned char>(
type))
1634 throw std::logic_error(
1635 "Unknown TObject2D type found while reading stream");
1641 out << static_cast<uint16_t>(o.
getType());
1676 switch (static_cast<unsigned char>(
type))
1719 throw std::logic_error(
1720 "Unknown TObject3D type found while reading stream");
1726 out << static_cast<uint16_t>(o.
getType());
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.
std::vector< T1 > operator-(const std::vector< T1 > &v1, const std::vector< T2 > &v2)
static void getSegments(const std::vector< TObject2D > &objs, std::vector< TSegment2D > &sgms)
Static method to retrieve all the segments in a vector of TObject2D.
bool getPoint(TPoint2D &p) const
Gets the content as a point, returning false if the type is inadequate.
void generateAxisBaseFromDirectionAndAxis(const double(&vec)[3], uint8_t coord, CMatrixDouble44 &matrix)
Creates a homogeneus matrix (4x4) such that the coordinate given (0 for x, 1 for y, 2 for z) corresponds to the provided vector.
static void createRegularPolygon(size_t numEdges, double radius, TPolygon3D &poly)
Static method to create a regular polygon, given its size and radius.
static void createRegularPolygon(size_t numEdges, double radius, TPolygon2D &poly)
Static method to create a regular polygon, given its size and radius.
void inverseComposePoint(const TPoint3D &g, TPoint3D &l) const
bool getPolygon(TPolygon2D &p) const
Gets the content as a polygon, returning false if the type is inadequate.
void rotate(const double ang)
Transform the (vx,vy) components for a counterclockwise rotation of ang radians.
double x
X,Y,Z coordinates.
static void SO3_to_yaw_pitch_roll(const mrpt::math::CMatrixDouble33 &R, double &yaw, double &pitch, double &roll)
unsigned __int16 uint16_t
double RAD2DEG(const double x)
Radians to degrees.
unsigned char getType() const
Gets content type.
bool operator==(const TTwist3D &o) const
void getRotationMatrix(mrpt::math::CMatrixDouble33 &R) const
#define THROW_EXCEPTION(msg)
double distance(const TPoint3D &point) const
Distance between the line and a point.
static constexpr unsigned char GEOMETRIC_TYPE_POLYGON
Object type identifier for TPolygon2D or TPolygon3D.
void getPlotData(std::vector< double > &x, std::vector< double > &y) const
Gets plot data, ready to use on a 2D plot.
size_t size(const MATRIXLIKE &m, const int dim)
bool isSkew() const
Check whether the polygon is skew.
bool getSegment(TSegment3D &s) const
Gets the content as a segment, returning false if the type is not adequate.
bool contains(const TPoint2D &point) const
Check whether a point is inside a segment.
double roll
Roll coordinate (rotation angle over X coordinate).
static void getPolygons(const std::vector< TObject2D > &objs, std::vector< TPolygon2D > &polys)
Static method to retrieve all the polygons in a vector of TObject2D.
double DEG2RAD(const double x)
Degrees to radians.
mrpt::math::TPoint2D composePoint(const TPoint2D l) const
TPolygon3D()
Default constructor.
GLdouble GLdouble GLdouble GLdouble q
double distance(const TPoint2D &point) const
Distance to point.
static void getLines(const std::vector< TObject2D > &objs, std::vector< TLine2D > &lins)
Static method to retrieve all the lines in a vector of TObject2D.
This file implements several operations that operate element-wise on individual or pairs of container...
mrpt::math::CMatrixDouble33 getRotationMatrix() const
double norm() const
Point norm: |v| = sqrt(x^2+y^2+z^2)
double signedDistance(const TPoint2D &point) const
Distance with sign from a given point (sign indicates side).
Standard type for storing any lightweight 2D type.
bool getLine(TLine2D &r) const
Gets the content as a line, returning false if the type is inadequate.
void getAsSegmentList(std::vector< TSegment2D > &v) const
Gets as set of segments, instead of points.
static constexpr unsigned char GEOMETRIC_TYPE_POINT
Object type identifier for TPoint2D or TPoint3D.
bool getPlane(TPlane &p) const
Gets the content as a plane, returning false if the type is not adequate.
TPoint3D pBase
Base point.
Standard object for storing any 3D lightweight object.
bool getSegment(TSegment2D &s) const
Gets the content as a segment, returning false if the type is inadequate.
bool contains(const TPoint2D &point) const
Check whether a point is inside the line.
void removeRepeatedVertices()
Erase repeated vertices.
double signedDistance(const TPoint2D &point) const
Distance with sign to point (sign indicates which side the point is).
void getInverseHomogeneousMatrix(mrpt::math::CMatrixDouble44 &HG) const
void generate3DObject(TLine3D &l) const
Project into 3D space, setting the z to 0.
void removeRepVertices(T &poly)
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -45...
void getAsPose2D(TPose2D &outPose) const
double distance(const TPoint3D &point) const
Distance to 3D point.
double yaw
Yaw coordinate (rotation angle over Z axis).
GLsizei GLsizei GLuint * obj
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[vx vy vz wx wy wz]" ) ...
mrpt::math::CMatrixDouble44 getHomogeneousMatrix() const
bool operator<(const TSegment3D &s) const
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
GLubyte GLubyte GLubyte GLubyte w
3D twist: 3D velocity vector (vx,vy,vz) + angular velocity (wx,wy,wz)
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
TPoint3D point1
Origin point.
bool conformAPlane(const std::vector< TPoint3D > &points)
Checks whether this polygon or set of points acceptably fits a plane.
static void getSegments(const std::vector< TObject3D > &objs, std::vector< TSegment3D > &sgms)
Static method to retrieve every segment included in a vector of objects.
void asVector(VECTORLIKE &v) const
Transformation into vector.
void generate2DObject(TLine2D &l) const
Project into 2D space, discarding the Z coordinate.
2D twist: 2D velocity vector (vx,vy) + planar angular velocity (omega)
T square(const T x)
Inline function for the square of a number.
void getNormalVector(double(&vector)[2]) const
Get line's normal vector.
void generate3DObject(TPolygon3D &p) const
Projects into 3D space, zeroing the z.
bool contains(const TPoint3D &point) const
Check whether a point is inside the line.
double isLeft(const mrpt::math::TPoint2D &P0, const mrpt::math::TPoint2D &P1, const mrpt::math::TPoint2D &P2)
static constexpr unsigned char GEOMETRIC_TYPE_PLANE
Object type identifier for TPlane.
void loadFromArray(const VECTOR &vals)
void unitarize()
Unitarize line's normal vector.
CMatrixFixed< double, 3, 3 > CMatrixDouble33
std::string asString() const
void getBoundingBox(TPoint2D &min_coords, TPoint2D &max_coords) const
Get polygon bounding box.
bool getPolygon(TPolygon3D &p) const
Gets the content as a polygon, returning false if the type is not adequate.
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
double distance(const TPoint3D &point) const
Distance to point.
void getUnitaryNormalVector(double(&vec)[3]) const
Get normal vector.
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -45...
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
3D segment, consisting of two points.
TSegment2D()=default
Fast default constructor.
double length() const
Segment length.
std::array< double, 3 > director
Director vector.
void fromHomogeneousMatrix(const mrpt::math::CMatrixDouble44 &HG)
TPoint3D point2
Destiny point.
bool operator<(const TSegment2D &s) const
double vx
Velocity components: X,Y (m/s)
auto block(int start_row, int start_col)
non-const block(): Returns an Eigen::Block reference to the block
mrpt::math::TPose2D operator+(const mrpt::math::TPose2D &b) const
Operator "oplus" pose composition: "ret=this \oplus b".
mrpt::math::TPoint2D inverseComposePoint(const TPoint2D g) const
constexpr TPose3D()=default
Default fast constructor.
constexpr TPose2D()=default
Default fast constructor.
static void getLines(const std::vector< TObject3D > &objs, std::vector< TLine3D > &lins)
Static method to retrieve every line included in a vector of objects.
void unitarize()
Unitarize normal vector.
mrpt::math::TPose2D operator*(const double dt) const
Returns the pose increment of multiplying each twist component times "dt" seconds.
void getAsQuaternion(mrpt::math::CQuaternion< double > &q, mrpt::math::CMatrixFixed< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
void generate2DObject(TPolygon2D &p) const
Projects into a 2D space, discarding the z.
static void getPolygons(const std::vector< TObject3D > &objs, std::vector< TPolygon3D > &polys)
Static method to retrieve every polygon included in a vector of objects.
3D Plane, represented by its equation
bool getPlane(TPlane &p) const
Gets a plane which contains the polygon.
double getRegressionPlane(const std::vector< TPoint3D > &points, TPlane &plane)
Using eigenvalues, gets the best fitting plane for a set of 3D points.
TPolygon2D()
Default constructor.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
void removeRedundantVertices()
Erase every redundant vertex, thus saving space.
bool fromMatlabStringFormat(const std::string &s, mrpt::optional_ref< std::ostream > dump_errors_here=std::nullopt)
Reads a matrix from a string in Matlab-like format, for example: "[1 0 2; 0 4 -1]" The string must st...
TPoint2D point2
Destiny point.
void getCenter(TPoint2D &p) const
Polygon's central point.
void rotate(const mrpt::math::TPose3D &rot)
Transform all 6 components for a change of reference frame from "A" to another frame "B" whose rotati...
double getAngle(const TPlane &p1, const TPlane &p2)
Computes the angle between two planes.
GLsizei const GLchar ** string
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
TVector3D getNormalVector() const
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
void unitarize()
Unitarize director vector.
static constexpr unsigned char GEOMETRIC_TYPE_UNDEFINED
Object type identifier for empty TObject2D or TObject3D.
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
bool contains(const TPoint3D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
bool getPoint(TPoint3D &p) const
Gets the content as a point, returning false if the type is not adequate.
double pitch
Pitch coordinate (rotation angle over Y axis).
Lightweight 3D pose (three spatial coordinates, plus a quaternion ).
double distance(const TPoint3D &point) const
Distance to point (always >=0)
TPoint2D point1
Origin point.
bool isConvex() const
Checks whether is convex.
void getHomogeneousMatrix(mrpt::math::CMatrixDouble44 &HG) const
#define ASSERTDEBMSG_(f, __ERROR_MSG)
void generate3DObject(TSegment3D &s) const
Project into 3D space, setting the z to 0.
bool contains(const TPoint2D &point) const
Check whether a point is inside (or within geometryEpsilon of a polygon edge).
void removeUnusedVertices(T &poly)
double distance(const TPoint2D &point) const
Distance to a point (always >=0)
constexpr TPoint3D()
Default constructor.
std::array< double, 3 > coefs
Line coefficients, stored as an array: .
void getAsPose2DForcingOrigin(const TPoint2D &origin, TPose2D &outPose) const
constexpr std::size_t size() const
const_iterator begin() const
double wx
Angular velocity (rad/s)
Virtual base class for "archives": classes abstracting I/O streams.
double vx
Velocity components: X,Y (m/s)
void generate3DObject(TObject3D &obj) const
Project into 3D space.
void homogeneousMatrixInverse(const MATRIXLIKE1 &M, MATRIXLIKE2 &out_inverse_M)
Efficiently compute the inverse of a 4x4 homogeneous matrix by only transposing the rotation 3x3 part...
static void getPoints(const std::vector< TObject2D > &objs, std::vector< TPoint2D > &pnts)
Static method to retrieve all the points in a vector of TObject2D.
void getPrismBounds(const std::vector< TPoint3D > &poly, TPoint3D &pMin, TPoint3D &pMax)
Gets the prism bounds of a 3D polygon or set of 3D points.
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0...
#define ASSERT_ABOVE_(__A, __B)
mrpt::math::CMatrixDouble44 getInverseHomogeneousMatrix() const
bool operator!=(const TTwist3D &o) const
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
void getAsPose3D(mrpt::math::TPose3D &outPose) const
void removeRedundantVertices()
Erase every redundant vertex from the polygon, saving space.
void removeRepeatedVertices()
Remove polygon's repeated vertices.
bool contains(const TPoint3D &point) const
Check whether a point is inside the segment.
bool getLine(TLine3D &r) const
Gets the content as a line, returning false if the type is not adequate.
double evaluatePoint(const TPoint3D &point) const
Evaluate a point in the plane's equation.
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
std::string asString() const
void generate2DObject(TSegment2D &s) const
Projection into 2D space, discarding the z.
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0...
void generate2DObject(TObject2D &obj) const
Projects into 2D space.
TLine3D()=default
Fast default constructor.
bool operator<(const TPoint3D &p) const
double evaluatePoint(const TPoint2D &point) const
Evaluate point in the line's equation.
CMatrixFixed< Scalar, BLOCK_ROWS, BLOCK_COLS > blockCopy(int start_row=0, int start_col=0) const
const blockCopy(): Returns a copy of the given block
GLfloat GLfloat GLfloat v2
unsigned char getType() const
Gets object type.
mrpt::math::TPose2D operator-(const mrpt::math::TPose2D &b) const
Operator "ominus" pose composition: "ret=this \ominus b".
static constexpr unsigned char GEOMETRIC_TYPE_SEGMENT
Object type identifier for TSegment2D or TSegment3D.
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ...
double distance(const TPoint2D &point) const
Distance from a given point.
void getAsSegmentList(std::vector< TSegment3D > &v) const
Gets as set of segments, instead of set of points.
void getBestFittingPlane(TPlane &p) const
Gets the best fitting plane, disregarding whether the polygon actually fits inside or not...
void getDirectorVector(double(&vector)[2]) const
Get line's director vector.
bool operator<(const COccupancyGridMap2D::TPairLikelihoodIndex &e1, const COccupancyGridMap2D::TPairLikelihoodIndex &e2)
std::string asString() const
CMatrixFixed< double, 4, 4 > CMatrixDouble44
TLine2D()=default
Fast default constructor.
TPlane()=default
Fast default constructor.
std::array< double, 4 > coefs
Plane coefficients, stored as an array: .
GLsizei GLsizei GLenum GLenum const GLvoid * data
std::string asString() const
GLubyte GLubyte GLubyte a
static void getPlanes(const std::vector< TObject3D > &objs, std::vector< TPlane > &plns)
Static method to retrieve every plane included in a vector of objects.
double phi
Orientation (rads)
GLuint GLuint GLsizei GLenum type
static constexpr unsigned char GEOMETRIC_TYPE_LINE
Object type identifier for TLine2D or TLine3D.
void operator()(const T &o)
2D polygon, inheriting from std::vector<TPoint2D>.
3D polygon, inheriting from std::vector<TPoint3D>
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
void getCenter(TPoint3D &p) const
Get polygon's central point.
double omega
Angular velocity (rad/s)
bool contains(const TPoint3D &point) const
Check whether a point is contained into the plane.
double length() const
Segment length.
void composePoint(const TPoint3D &l, TPoint3D &g) const
bool operator!=(const TTwist2D &o) const
void getAsPose3DForcingOrigin(const TPoint3D ¢er, TPose3D &pose) const
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0...
bool operator==(const TTwist2D &o) const
3D line, represented by a base point and a director vector.
void composePose(const TPose3D other, TPose3D &result) const
2D line without bounds, represented by its equation .
static void getPoints(const std::vector< TObject3D > &objs, std::vector< TPoint3D > &pnts)
Static method to retrieve every point included in a vector of objects.