Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volume below a plane #219

Merged
merged 88 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 86 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
56b214e
Add volume below primitives
arjo129 Aug 3, 2021
008aa1b
fix tests
arjo129 Aug 5, 2021
0e40a5f
nearly there for boxes
arjo129 Aug 5, 2021
c18b735
Fix boxes
arjo129 Aug 6, 2021
40fa5b3
use convex hull algo
arjo129 Aug 9, 2021
e275ff8
Add overlap method
arjo129 Aug 10, 2021
dfec15c
Finally `Box::VolumeBelow()` works :tada:
arjo129 Aug 11, 2021
13f0ade
signed volume
arjo129 Aug 12, 2021
5cfe42c
codecheck
arjo129 Aug 12, 2021
d82a6ba
Add center of volume recalculation
arjo129 Aug 14, 2021
27287dc
Add center of volume functions
arjo129 Aug 14, 2021
f241019
codecheck
arjo129 Aug 14, 2021
61258cd
Trying to get windows CI to pass
arjo129 Aug 14, 2021
69af275
Add preliminary cylinder logic.
arjo129 Aug 16, 2021
3095359
Add plane transformation
arjo129 Aug 19, 2021
37b3842
fix function return value
arjo129 Aug 26, 2021
bbed807
fix types
arjo129 Aug 26, 2021
c6c7e00
Preliminary work for cylinders
arjo129 Aug 29, 2021
278dc07
remove unessecary include
arjo129 Aug 30, 2021
f4e70c7
remove more useless logging
arjo129 Aug 30, 2021
11180ee
remove unused transform function.
arjo129 Aug 30, 2021
6521336
style fixes
arjo129 Aug 30, 2021
532775b
:facepalm: compilation error
arjo129 Aug 30, 2021
a90d11a
more style fixes.
arjo129 Aug 30, 2021
a30d0db
Merge branch 'ign-math6' into arjo/volume_below
arjo129 Aug 30, 2021
4d6675d
Fix docstring
arjo129 Aug 30, 2021
2578996
Revert changes to cylinder since those are not ready yet.
arjo129 Aug 30, 2021
482f582
more cleanups
arjo129 Aug 30, 2021
4888d99
Add triangle test
arjo129 Aug 30, 2021
e1985b3
Remove redundant function
arjo129 Aug 30, 2021
7f204d4
>.< Doh stray include
arjo129 Aug 30, 2021
99589e4
remove unused include
arjo129 Aug 30, 2021
5ee6f3b
typesafe-ify
arjo129 Aug 31, 2021
1c896fa
silence warning
arjo129 Sep 1, 2021
646595f
Codecheck
arjo129 Sep 1, 2021
e8fd7a2
Flip sign... :facepalm:
arjo129 Sep 1, 2021
6f82675
Merge branch 'ign-math6' into arjo/volume_below
arjo129 Sep 2, 2021
43fd3e3
Merge branch 'ign-math6' into arjo/volume_below
chapulina Sep 14, 2021
16289b0
Rename `Box::GetIntersections`.
arjo129 Sep 15, 2021
9ed6254
Merge branch 'arjo/volume_below' of github.com:ignitionrobotics/ign-m…
arjo129 Sep 15, 2021
1257aca
Revert *all* changes to cylinder
arjo129 Sep 15, 2021
7f1f1c8
fix docs and signature
arjo129 Sep 15, 2021
6ff1b49
Add line test
arjo129 Sep 15, 2021
753b49d
style fix
arjo129 Sep 15, 2021
633dfee
Documentation
arjo129 Sep 15, 2021
165a724
Fix compiler :warning:
arjo129 Sep 15, 2021
f5a45fa
Added test for `Vector3d::Project()`
arjo129 Sep 16, 2021
e7eaad6
Add test for CenterOfVolumeBelow()
arjo129 Sep 16, 2021
9739419
Add Vector(2|3|4)<T>::NaN to easily create invalid vectors (#222)
chapulina Sep 15, 2021
9fef0d9
style
arjo129 Sep 16, 2021
5a20d68
update intersections test
arjo129 Sep 16, 2021
e6e6e65
Removed `GetPointOnPlane` as its unessescary
arjo129 Sep 16, 2021
7189fe0
fix :warning: about signess
arjo129 Sep 16, 2021
d98acb7
Update include/ignition/math/Box.hh
arjo129 Sep 16, 2021
8cfbb7d
Rename intersections
arjo129 Sep 17, 2021
cf438da
Rename Vector projection
arjo129 Sep 17, 2021
aed0c6b
Add tolerance argument
arjo129 Sep 17, 2021
c835aee
Update line to point distance to support points projected beyond the …
chapulina Sep 16, 2021
b1a172f
Suggestions to #219
chapulina Sep 16, 2021
9979f83
🌐 Spherical coordinates: bug fix, docs and sanity checks (#235)
chapulina Sep 16, 2021
5c9343f
Adds python interface to Quaternion, Pose3, Matrix3 and Matrix4 (#221)
LolaSegura Sep 17, 2021
495583d
fixes
arjo129 Sep 20, 2021
305d4d4
Rigorous tests and bugfixes
arjo129 Sep 20, 2021
aba72c1
Style
arjo129 Sep 20, 2021
0b8c218
more fixes
arjo129 Sep 20, 2021
acacbb9
fix compile issues caused by merge
arjo129 Sep 20, 2021
b1a36c0
More comprehensive tests and bugfixes for box
arjo129 Sep 20, 2021
d8bae9a
Merge branch 'ign-math6' into arjo/volume_below
arjo129 Sep 20, 2021
8e75628
fix windows warning (I think)
arjo129 Sep 20, 2021
9a66163
Add plane intersection in bounds
arjo129 Sep 20, 2021
4bf9cfb
style
arjo129 Sep 20, 2021
d0c605d
style
arjo129 Sep 20, 2021
d4968df
More suggestions to #219
chapulina Sep 21, 2021
9a659fe
abs, include
chapulina Sep 21, 2021
70aa913
Merge pull request #243 from ignitionrobotics/chapulina/volume_below_2
arjo129 Sep 21, 2021
f8d1a7a
Merge branch 'ign-math6' into arjo/volume_below
arjo129 Sep 21, 2021
95cd4ee
Fixed header
arjo129 Sep 21, 2021
20d66b1
Workaround. Hopefully will make windows happy.
arjo129 Sep 21, 2021
1492375
Address @scpeter 's feedback
arjo129 Sep 21, 2021
72d7779
Address @scpeters feedback about Line3
arjo129 Sep 21, 2021
e356258
Reverting, because the dividee by zero will never occur
arjo129 Sep 21, 2021
b06b483
Added comment
arjo129 Sep 21, 2021
91a6b43
Add test cases and assert
arjo129 Sep 21, 2021
f547e71
Whelps compile error.
arjo129 Sep 21, 2021
69b0448
Add docs
arjo129 Sep 21, 2021
bacd9f9
whitespaces
arjo129 Sep 21, 2021
4c0bd02
More docs fixes
arjo129 Sep 21, 2021
b4f9ddc
update scalar value
arjo129 Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion include/ignition/math/Box.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@
#include <ignition/math/config.hh>
#include <ignition/math/MassMatrix3.hh>
#include <ignition/math/Material.hh>
#include <ignition/math/Plane.hh>
arjo129 marked this conversation as resolved.
Show resolved Hide resolved
#include <ignition/math/Vector3.hh>

#include "ignition/math/detail/WellOrderedVector.hh"

#include <set>

namespace ignition
{
namespace math
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_MATH_VERSION_NAMESPACE {
//
/// \brief This is the type used for deduplicating and returning the set of
/// intersections.
template<typename T>
using IntersectionPoints = std::set<Vector3<T>, WellOrderedVectors<T>>;

/// \class Box Box.hh ignition/math/Box.hh
/// \brief A representation of a box. All units are in meters.
///
Expand Down Expand Up @@ -128,6 +137,28 @@ namespace ignition
/// \return Volume of the box in m^3.
public: Precision Volume() const;

/// \brief Get the volume of the box below a plane.
/// \param[in] _plane The plane which cuts the box, expressed in the box's
/// frame.
/// \return Volume below the plane in m^3.
public: Precision VolumeBelow(const Plane<Precision> &_plane) const;

/// \brief Center of volume below the plane. This is useful when
/// calculating where buoyancy should be applied, for example.
/// \param[in] _plane The plane which cuts the box, expressed in the box's
/// frame.
/// \return Center of volume, in box's frame.
public: std::optional<Vector3<Precision>>
CenterOfVolumeBelow(const Plane<Precision> &_plane) const;

/// \brief All the vertices which are on or below the plane.
/// \param[in] _plane The plane which cuts the box, expressed in the box's
/// frame.
/// \return Box vertices which are below the plane, expressed in the box's
/// frame.
public: IntersectionPoints<Precision>
VerticesBelow(const Plane<Precision> &_plane) const;

/// \brief Compute the box's density given a mass value. The
/// box is assumed to be solid with uniform density. This
/// function requires the box's size to be set to
Expand Down Expand Up @@ -161,6 +192,14 @@ namespace ignition
/// could be due to an invalid size (<=0) or density (<=0).
public: bool MassMatrix(MassMatrix3<Precision> &_massMat) const;

/// \brief Get intersection between a plane and the box's edges.
/// Edges contained on the plane are ignored.
/// \param[in] _plane The plane against which we are testing intersection.
/// \returns A list of points along the edges of the box where the
/// intersection occurs.
public: IntersectionPoints<Precision> Intersections(
const Plane<Precision> &_plane) const;

/// \brief Size of the box.
private: Vector3<Precision> size = Vector3<Precision>::Zero;

Expand Down
30 changes: 30 additions & 0 deletions include/ignition/math/Line3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,36 @@ namespace ignition
return true;
}

/// \brief Calculate shortest distance between line and point
/// \param[in] _pt Point which we are measuring distance to.
/// \returns Distance from point to line.
public: T Distance(const Vector3<T> &_pt)
{
auto line = this->pts[1] - this->pts[0];
auto ptTo0 = _pt - this->pts[0];
auto ptTo1 = _pt - this->pts[1];

// Point is projected beyond pt0 or the line has length 0
if (ptTo0.Dot(line) <= 0.0)
{
return ptTo0.Length();
}

// Point is projected beyond pt1
if (ptTo1.Dot(line) >= 0.0)
{
return ptTo1.Length();
}

// Distance to point projected onto line
// line.Length() will have to be > 0 at this point otherwise it would
// return at line 244.
auto d = ptTo0.Cross(line);
auto lineLength = line.Length();
assert(lineLength > 0);
return d.Length() / lineLength;
}

/// \brief Check if this line intersects the given line segment.
/// \param[in] _line The line to check for intersection.
/// \param[in] _epsilon The error bounds within which the intersection
Expand Down
49 changes: 49 additions & 0 deletions include/ignition/math/Plane.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <ignition/math/Vector2.hh>
#include <ignition/math/Vector3.hh>
#include <ignition/math/config.hh>
#include <ignition/math/Line2.hh>
#include <ignition/math/Quaternion.hh>
#include <optional>

namespace ignition
{
Expand Down Expand Up @@ -119,6 +122,52 @@ namespace ignition
return this->normal.Dot(_point) - this->d;
}

/// \brief Get the intersection of an infinite line with the plane,
/// given the line's gradient and a point in parametrized space.
/// \param[in] _point A point that lies on the line.
/// \param[in] _gradient The gradient of the line.
/// \param[in] _tolerance The tolerance for determining a line is
/// parallel to the plane. Optional, default=10^-16
/// \return The point of intersection. std::nullopt if the line is
/// parallel to the plane (including lines on the plane).
public: std::optional<Vector3<T>> Intersection(
const Vector3<T> &_point,
const Vector3<T> &_gradient,
const double &_tolerance = 1e-6) const
{
if (std::abs(this->Normal().Dot(_gradient)) < _tolerance)
{
return std::nullopt;
}
auto constant = this->Offset() - this->Normal().Dot(_point);
auto param = constant / this->Normal().Dot(_gradient);
auto intersection = _point + _gradient*param;

if (this->Size() == Vector2<T>(0, 0))
return intersection;

// Check if the point is within the size bounds
// To do this we create a Quaternion using Angle, Axis constructor and
// rotate the Y and X axis the same amount as the normal.
auto dotProduct = Vector3<T>::UnitZ.Dot(this->Normal());
auto angle = acos(dotProduct / this->Normal().Length());
auto axis = Vector3<T>::UnitZ.Cross(this->Normal().Normalized());
Quaternion<T> rotation(axis, angle);

Vector3<T> rotatedXAxis = rotation * Vector3<T>::UnitX;
Vector3<T> rotatedYAxis = rotation * Vector3<T>::UnitY;

auto xBasis = rotatedXAxis.Dot(intersection);
auto yBasis = rotatedYAxis.Dot(intersection);
chapulina marked this conversation as resolved.
Show resolved Hide resolved

if (std::abs(xBasis) < this->Size().X() / 2 &&
std::abs(yBasis) < this->Size().Y() / 2)
{
return intersection;
}
return std::nullopt;
}

/// \brief The side of the plane a point is on.
/// \param[in] _point The 3D point to check.
/// \return Plane::NEGATIVE_SIDE if the distance from the point to the
Expand Down
18 changes: 18 additions & 0 deletions include/ignition/math/Sphere.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ignition/math/MassMatrix3.hh"
#include "ignition/math/Material.hh"
#include "ignition/math/Quaternion.hh"
#include "ignition/math/Plane.hh"

namespace ignition
{
Expand Down Expand Up @@ -91,6 +92,23 @@ namespace ignition
/// \return Volume of the sphere in m^3.
public: Precision Volume() const;

/// \brief Get the volume of sphere below a given plane in m^3.
/// It is assumed that the center of the sphere is on the origin
/// \param[in] _plane The plane which slices this sphere, expressed
/// in the sphere's reference frame.
/// \return Volume below the sphere in m^3.
public: Precision VolumeBelow(const Plane<Precision> &_plane) const;

/// \brief Center of volume below the plane. This is useful for example
/// when calculating where buoyancy should be applied.
/// \param[in] _plane The plane which slices this sphere, expressed
/// in the sphere's reference frame.
/// \return The center of volume if there is anything under the plane,
/// otherwise return a std::nullopt. Expressed in the sphere's reference
/// frame.
public: std::optional<Vector3<Precision>>
CenterOfVolumeBelow(const Plane<Precision> &_plane) const;

/// \brief Compute the sphere's density given a mass value. The
/// sphere is assumed to be solid with uniform density. This
/// function requires the sphere's radius to be set to a
Expand Down
2 changes: 1 addition & 1 deletion include/ignition/math/Vector3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace ignition
return n.Normalize();
}

/// \brief Get distance to a line
/// \brief Get distance to an infinite line defined by 2 points.
/// \param[in] _pt1 first point on the line
/// \param[in] _pt2 second point on the line
/// \return the minimum distance from this point to the line
Expand Down
Loading