Skip to content

Commit

Permalink
Merge pull request #30 from open-space-collective/users/lucas/improve…
Browse files Browse the repository at this point in the history
…-geometry

Add geometry queries
  • Loading branch information
lucas-bremond authored Jul 18, 2019
2 parents 5810552 + 2f2ea61 commit f1ff325
Show file tree
Hide file tree
Showing 19 changed files with 1,760 additions and 230 deletions.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ The **Mathematics** library exhibits the following structure:
│ │ │ ├── Line
│ │ │ ├── Ray
│ │ │ ├── Segment
│ │ │ ├── Rectangle
│ │ │ ├── Line String
│ │ │ ├── Polygon
│ │ │ ├── Plane
│ │ │ ├── Cuboid
│ │ │ ├── Sphere
│ │ │ ├── Ellipsoid
│ │ │ ├── Cone
│ │ │ └── Pyramid
│ │ │ ├── Pyramid
│ │ │ └── Composite
│ │ ├── Intersection
│ │ └── Transformations
│ │ ├── Identity
Expand Down Expand Up @@ -109,6 +112,51 @@ Various tutorials are available here:
- [C++](./tutorials/cpp)
- [Python](./tutorials/python)

## Features

### Geometry Queries

- ``: query only
- ``: query / intersection set
- ` `: to be implemented
- `-`: undefined

#### 3D

| Intersect | Point | Point Set | Line | Ray | Segment | Line String | Polygon | Plane | Cuboid | Sphere | Ellipsoid | Cone | Pyramid | Composite |
|------------------|-------|-----------|------|-----|---------|-------------|---------|-------|--------|--------|-----------|------|---------|-----------|
| **Point** | | ||| | | ||||| | | |
| **Point Set** | | | | | | | ||||| | | |
| **Line** || | | | | | ||||| | | |
| **Ray** || | | | | | || ||| | | |
| **Segment** | | | | | | | || ||| | | |
| **Line String** | | | | | | | | | | | | | | |
| **Polygon** | | | | | | | | | | | | | | |
| **Plane** |||||| | | | ||| | | |
| **Cuboid** |||| | | | | | | | | | | |
| **Sphere** |||||| | || | | | || |
| **Ellipsoid** |||||| | || | | ||| |
| **Cone** | | | | | | | | | | || | | |
| **Pyramid** | | | | | | | | | ||| | | |
| **Composite** | | | | | | | | | | | | | | |

| Contain | Point | Point Set | Line | Ray | Segment | Line String | Polygon | Plane | Cuboid | Sphere | Ellipsoid | Cone | Pyramid | Composite |
|------------------|-------|-----------|------|-----|---------|-------------|---------|-------|--------|--------|-----------|------|---------|-----------|
| **Point** | | | - | - | - | - | - | - | - | - | - | - | - | |
| **Point Set** | | | - | - | - | - | - | - | - | - | - | - | - | |
| **Line** || | | | | | - | - | - | - | - | - | - | |
| **Ray** ||| - | | | | - | - | - | - | - | - | - | |
| **Segment** || | - | - | | | - | - | - | - | - | - | - | |
| **Line String** | | | - | - | | | - | - | - | - | - | - | - | |
| **Polygon** | | | - | - | | | | - | - | - | - | - | - | |
| **Plane** |||||| | | | - | - | - | - | - | |
| **Cuboid** ||| - | - | | | | - | | | | | | |
| **Sphere** ||| - | - | - | - | - | - | | | | | | |
| **Ellipsoid** ||| - | - | - | - | - | - | | | | | | |
| **Cone** | | | | | | - | - | - | | | | | | |
| **Pyramid** || | | | | | | - | | | | | | |
| **Composite** | | | | | | | | | | | | | | |

## Setup

### Development
Expand Down Expand Up @@ -182,4 +230,4 @@ Please read our [contributing guide](CONTRIBUTING.md) to learn about our develop

## License

Apache License 2.0
Apache License 2.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Line (
using library::math::geom::d3::Object ;
using library::math::geom::d3::objects::Point ;
using library::math::geom::d3::objects::Line ;
using library::math::geom::d3::objects::Plane ;
using library::math::geom::d3::objects::Sphere ;
using library::math::geom::d3::objects::Ellipsoid ;
using library::math::geom::d3::Intersection ;

scope in_Line = class_<Line, bases<Object>>("Line", init<const Point&, const Vector3d&>())

Expand All @@ -33,18 +35,20 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Line (

.def("isDefined", &Line::isDefined)
.def("intersectsPoint", +[] (const Line& aLine, const Point& aPoint) -> bool { return aLine.intersects(aPoint) ; })
.def("intersectsPlane", +[] (const Line& aLine, const Plane& aPlane) -> bool { return aLine.intersects(aPlane) ; })
.def("intersectsSphere", +[] (const Line& aLine, const Sphere& aSphere) -> bool { return aLine.intersects(aSphere) ; })
.def("intersectsEllipsoid", +[] (const Line& aLine, const Ellipsoid& anEllipsoid) -> bool { return aLine.intersects(anEllipsoid) ; })
.def("containsPoint", +[] (const Line& aLine, const Point& aPoint) -> bool { return aLine.contains(aPoint) ; })

.def("getOrigin", &Line::getOrigin)
.def("getDirection", &Line::getDirection)
.def("intersectionWithPlane", +[] (const Line& aLine, const Plane& aPlane) -> Intersection { return aLine.intersectionWith(aPlane) ; })
.def("applyTransformation", &Line::applyTransformation)

.def("Undefined", &Line::Undefined).staticmethod("Undefined")

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Plane (
using library::math::obj::Vector3d ;
using library::math::geom::d3::Object ;
using library::math::geom::d3::objects::Point ;
using library::math::geom::d3::objects::PointSet ;
using library::math::geom::d3::objects::Plane ;
using library::math::geom::d3::objects::Line ;
using library::math::geom::d3::objects::Ray ;
using library::math::geom::d3::objects::Segment ;
using library::math::geom::d3::Intersection ;

scope in_Plane = class_<Plane, bases<Object>>("Plane", init<const Point&, const Vector3d&>())

Expand All @@ -28,18 +33,32 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Plane (

.def(self_ns::str(self_ns::self))
.def(self_ns::repr(self_ns::self))

.def("isDefined", &Plane::isDefined)
.def("intersectsPoint", +[] (const Plane& aPlane, const Point& aPoint) -> bool { return aPlane.intersects(aPoint) ; })
.def("intersectsPointSet", +[] (const Plane& aPlane, const PointSet& aPointSet) -> bool { return aPlane.intersects(aPointSet) ; })
.def("intersectsLine", +[] (const Plane& aPlane, const Line& aLine) -> bool { return aPlane.intersects(aLine) ; })
.def("intersectsRay", +[] (const Plane& aPlane, const Ray& aRay) -> bool { return aPlane.intersects(aRay) ; })
.def("intersectsSegment", +[] (const Plane& aPlane, const Segment& aSegment) -> bool { return aPlane.intersects(aSegment) ; })
.def("containsPoint", +[] (const Plane& aPlane, const Point& aPoint) -> bool { return aPlane.contains(aPoint) ; })
.def("containsPointSet", +[] (const Plane& aPlane, const PointSet& aPointSet) -> bool { return aPlane.contains(aPointSet) ; })
.def("containsLine", +[] (const Plane& aPlane, const Line& aLine) -> bool { return aPlane.contains(aLine) ; })
.def("containsRay", +[] (const Plane& aPlane, const Ray& aRay) -> bool { return aPlane.contains(aRay) ; })
.def("containsSegment", +[] (const Plane& aPlane, const Segment& aSegment) -> bool { return aPlane.contains(aSegment) ; })

.def("getPoint", &Plane::getPoint)
.def("getNormalVector", &Plane::getNormalVector)
.def("intersectionWithPoint", +[] (const Plane& aPlane, const Point& aPoint) -> Intersection { return aPlane.intersectionWith(aPoint) ; })
.def("intersectionWithPointSet", +[] (const Plane& aPlane, const PointSet& aPointSet) -> Intersection { return aPlane.intersectionWith(aPointSet) ; })
.def("intersectionWithLine", +[] (const Plane& aPlane, const Line& aLine) -> Intersection { return aPlane.intersectionWith(aLine) ; })
.def("intersectionWithRay", +[] (const Plane& aPlane, const Ray& aRay) -> Intersection { return aPlane.intersectionWith(aRay) ; })
.def("intersectionWithSegment", +[] (const Plane& aPlane, const Segment& aSegment) -> Intersection { return aPlane.intersectionWith(aSegment) ; })
.def("applyTransformation", &Plane::applyTransformation)

.def("Undefined", &Plane::Undefined).staticmethod("Undefined")

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Ray ( )
using library::math::obj::Vector3d ;
using library::math::geom::d3::Object ;
using library::math::geom::d3::objects::Point ;
using library::math::geom::d3::objects::PointSet ;
using library::math::geom::d3::objects::Ray ;
using library::math::geom::d3::objects::Plane ;
using library::math::geom::d3::objects::Sphere ;
Expand All @@ -35,20 +36,22 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Ray ( )

.def("isDefined", &Ray::isDefined)
.def("intersectsPoint", +[] (const Ray& aRay, const Point& aPoint) -> bool { return aRay.intersects(aPoint) ; })
.def("intersectsPlane", +[] (const Ray& aRay, const Plane& aPlane) -> bool { return aRay.intersects(aPlane) ; })
.def("intersectsSphere", +[] (const Ray& aRay, const Sphere& aSphere) -> bool { return aRay.intersects(aSphere) ; })
.def("intersectsEllipsoid", +[] (const Ray& aRay, const Ellipsoid& anEllipsoid) -> bool { return aRay.intersects(anEllipsoid) ; })
.def("containsPoint", +[] (const Ray& aRay, const Point& aPoint) -> bool { return aRay.contains(aPoint) ; })
.def("containsPointSet", +[] (const Ray& aRay, const PointSet& aPointSet) -> bool { return aRay.contains(aPointSet) ; })

.def("getOrigin", &Ray::getOrigin)
.def("getDirection", &Ray::getDirection)
.def("intersectionWithPlane", +[] (const Ray& aRay, const Plane& aPlane) -> Intersection { return aRay.intersectionWith(aPlane) ; })
.def("intersectionWithEllipsoid", +[] (const Ray& aRay, const Ellipsoid& anEllipsoid) -> Intersection { return aRay.intersectionWith(anEllipsoid) ; })
.def("applyTransformation", &Ray::applyTransformation)

.def("Undefined", &Ray::Undefined).staticmethod("Undefined")

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Segment
using library::math::geom::d3::Object ;
using library::math::geom::d3::objects::Point ;
using library::math::geom::d3::objects::Segment ;
using library::math::geom::d3::objects::Plane ;
using library::math::geom::d3::objects::Sphere ;
using library::math::geom::d3::objects::Ellipsoid ;
using library::math::geom::d3::Intersection ;

scope in_Segment = class_<Segment, bases<Object>>("Segment", init<const Point&, const Point&>())

Expand All @@ -32,6 +34,7 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Segment

.def("isDefined", &Segment::isDefined)
.def("isDegenerate", &Segment::isDegenerate)
.def("intersectsPlane", +[] (const Segment& aSegment, const Plane& aPlane) -> bool { return aSegment.intersects(aPlane) ; })
.def("intersectsSphere", +[] (const Segment& aSegment, const Sphere& aSphere) -> bool { return aSegment.intersects(aSphere) ; })
.def("intersectsEllipsoid", +[] (const Segment& aSegment, const Ellipsoid& anEllipsoid) -> bool { return aSegment.intersects(anEllipsoid) ; })
.def("containsPoint", +[] (const Segment& aSegment, const Point& aPoint) -> bool { return aSegment.contains(aPoint) ; })
Expand All @@ -41,12 +44,13 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Segment
.def("getCenter", &Segment::getCenter)
.def("getDirection", &Segment::getDirection)
.def("getLength", &Segment::getLength)
.def("intersectionWithPlane", +[] (const Segment& aSegment, const Plane& aPlane) -> Intersection { return aSegment.intersectionWith(aPlane) ; })
.def("applyTransformation", &Segment::applyTransformation)

.def("Undefined", &Segment::Undefined).staticmethod("Undefined")

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32 changes: 27 additions & 5 deletions include/Library/Mathematics/Geometry/3D/Objects/Line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ using library::math::geom::d3::objects::Point ;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class PointSet ;
class Plane ;
class Sphere ;
class Ellipsoid ;

Expand Down Expand Up @@ -110,11 +112,24 @@ class Line : public Object
/// line.intersects(point) ;
/// @endcode
///
/// @param [in] anPoint An point
/// @param [in] anPoint A point
/// @return True if line intersects point

bool intersects ( const Point& aPoint ) const ;

/// @brief Check if line intersects plane
///
/// @code
/// Line line = ... ;
/// Plane plane = ... ;
/// line.intersects(plane) ;
/// @endcode
///
/// @param [in] aPlane A plane
/// @return True if line intersects plane

bool intersects ( const Plane& aPlane ) const ;

/// @brief Check if line intersects sphere
///
/// @code
Expand All @@ -125,7 +140,7 @@ class Line : public Object
///
/// @param [in] aSphere A sphere
/// @return True if line intersects sphere

bool intersects ( const Sphere& aSphere ) const ;

/// @brief Check if line intersects ellipsoid
Expand All @@ -138,7 +153,7 @@ class Line : public Object
///
/// @param [in] anEllipsoid An ellipsoid
/// @return True if line intersects ellipsoid

bool intersects ( const Ellipsoid& anEllipsoid ) const ;

/// @brief Check if line contains point
Expand Down Expand Up @@ -174,6 +189,13 @@ class Line : public Object

Vector3d getDirection ( ) const ;

/// @brief Compute intersection of line with plane
///
/// @param [in] aPlane A plane
/// @return Intersection of line with plane

Intersection intersectionWith ( const Plane& aPlane ) const ;

/// @brief Print line
///
/// @param [in] anOutputStream An output stream
Expand Down Expand Up @@ -217,4 +239,4 @@ class Line : public Object

#endif

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Loading

0 comments on commit f1ff325

Please sign in to comment.