Skip to content

Commit

Permalink
Merge pull request #28 from open-space-collective/users/lucas/geometr…
Browse files Browse the repository at this point in the history
…y-queries

Geometry queries
  • Loading branch information
lucas-bremond authored Jul 17, 2019
2 parents dea65aa + 167e989 commit 57c72a9
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 71 deletions.
2 changes: 1 addition & 1 deletion bindings/python/docs/Reference/Geometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
162 changes: 162 additions & 0 deletions bindings/python/docs/Reference/Geometry/2D/Objects/Polygon.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Library ▸ Mathematics ▸ Geometry ▸ 2D ▸ Objects ▸ Polygon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import Library.Mathematics as Mathematics"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"Point = Mathematics.Geometry.D2.Objects.Point\n",
"PointSet = Mathematics.Geometry.D2.Objects.PointSet\n",
"Polygon = Mathematics.Geometry.D2.Objects.Polygon\n",
"Transformation = Mathematics.Geometry.D2.Transformation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Polygon"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Constructors**"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)], [[Point(0.5, 0.5), Point(0.5, 0.6), Point(0.6, 0.5)]])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"Polygon.Undefined() ;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Operators**"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"polygon == polygon ;\n",
"polygon != polygon ;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Methods**"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"polygon.isDefined() ;\n",
"polygon.intersectsPolygon(polygon) ;\n",
"polygon.containsPoint(Point(0.0, 0.0)) ;\n",
"polygon.containsPointSet(PointSet([Point(0.0, 0.0)])) ;\n",
"polygon.getInnerRingCount() ;\n",
"polygon.getEdgeCount() ;\n",
"polygon.getVertexCount() ;\n",
"polygon.getOuterRing() ;\n",
"polygon.getInnerRingAt(0) ;\n",
"polygon.getEdgeAt(0) ;\n",
"polygon.getVertexAt(0) ;\n",
"# polygon.getEdges() ;\n",
"polygon.getVertices() ;\n",
"polygon.toString() ;\n",
"polygon.applyTransformation(Transformation.Identity()) ;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ inline void LibraryMathematicsPy_Geometry_2D_Objects_Point (

.from_python<Array<Point>>()
.to_python<Array<Point>>()

.from_python<Array<Array<Point>>>()
.to_python<Array<Array<Point>>>()

;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ inline void LibraryMathematicsPy_Geometry_3D_Intersection (
.def("accessComposite", &Intersection::accessComposite, return_value_policy<reference_existing_object>())

.def("getType", &Intersection::getType)

.def("Undefined", &Intersection::Undefined).staticmethod("Undefined")
.def("Empty", &Intersection::Empty).staticmethod("Empty")
.def("Point", &Intersection::Point).staticmethod("Point")
.def("PointSet", &Intersection::PointSet).staticmethod("PointSet")

.def("Line", &Intersection::Line).staticmethod("Line")
.def("Ray", &Intersection::Ray).staticmethod("Ray")
.def("Segment", &Intersection::Segment).staticmethod("Segment")

.def("StringFromType", &Intersection::StringFromType).staticmethod("StringFromType")

;

enum_<Intersection::Type>("Type")

.value("Undefined", Intersection::Type::Undefined)
.value("Empty", Intersection::Type::Empty)
.value("Point", Intersection::Type::Point)
Expand All @@ -103,9 +106,9 @@ inline void LibraryMathematicsPy_Geometry_3D_Intersection (
.value("Sphere", Intersection::Type::Sphere)
.value("Ellipsoid", Intersection::Type::Ellipsoid)
.value("Complex", Intersection::Type::Complex)

;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Pyramid
.def("isDefined", &Pyramid::isDefined)
.def("intersectsEllipsoid", +[] (const Pyramid& aPyramid, const Ellipsoid& anEllipsoid) -> bool { return aPyramid.intersects(anEllipsoid) ; })
.def("intersectsEllipsoid", +[] (const Pyramid& aPyramid, const Ellipsoid& anEllipsoid, const Size aDiscretizationLevel) -> bool { return aPyramid.intersects(anEllipsoid, aDiscretizationLevel) ; })
.def("containsPoint", +[] (const Pyramid& aPyramid, const Point& aPoint) -> bool { return aPyramid.contains(aPoint) ; })
.def("containsEllipsoid", +[] (const Pyramid& aPyramid, const Ellipsoid& anEllipsoid) -> bool { return aPyramid.contains(anEllipsoid) ; })

.def("getBase", &Pyramid::getBase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Ray ( )
using library::math::geom::d3::Object ;
using library::math::geom::d3::objects::Point ;
using library::math::geom::d3::objects::Ray ;
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 ;
Expand All @@ -40,6 +41,7 @@ inline void LibraryMathematicsPy_Geometry_3D_Objects_Ray ( )

.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)

Expand Down
30 changes: 30 additions & 0 deletions include/Library/Mathematics/Geometry/3D/Intersection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,36 @@ class Intersection

static Intersection LineString ( const objects::LineString& aLineString ) ;

/// @brief Constructs a line intersection
///
/// @code
/// Intersection intersection = Intersection::Line(Line({ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 })) ;
/// @endcode
///
/// @return Line intersection

static Intersection Line ( const objects::Line& aLine ) ;

/// @brief Constructs a ray intersection
///
/// @code
/// Intersection intersection = Intersection::Ray(Ray({ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 })) ;
/// @endcode
///
/// @return Ray intersection

static Intersection Ray ( const objects::Ray& aRay ) ;

/// @brief Constructs a segment intersection
///
/// @code
/// Intersection intersection = Intersection::Segment(Segment({ 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 })) ;
/// @endcode
///
/// @return Segment intersection

static Intersection Segment ( const objects::Segment& aSegment ) ;

/// @brief Converts intersection type to string
///
/// @return String
Expand Down
13 changes: 13 additions & 0 deletions include/Library/Mathematics/Geometry/3D/Objects/Pyramid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ class Pyramid : public Object
bool intersects ( const Ellipsoid& anEllipsoid,
const Size aDiscretizationLevel = 40 ) const ;

/// @brief Check if pyramid contains point
///
/// @code
/// Pyramid pyramid = ... ;
/// Point point = ... ;
/// pyramid.contains(point) ;
/// @endcode
///
/// @param [in] aPoint A point
/// @return True if pyramid contains point

bool contains ( const Point& aPoint ) const ;

/// @brief Check if pyramid contains ellipsoid
///
/// @code
Expand Down
7 changes: 7 additions & 0 deletions include/Library/Mathematics/Geometry/3D/Objects/Ray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ class Ray : public Object

Vector3d getDirection ( ) const ;

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

Intersection intersectionWith ( const Plane& aPlane ) const ;

/// @brief Compute intersection of ray with sphere
///
/// @param [in] aSphere A sphere
Expand Down
39 changes: 39 additions & 0 deletions src/Library/Mathematics/Geometry/3D/Intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,45 @@ Intersection Intersection::LineString (

}

Intersection Intersection::Line ( const objects::Line& aLine )
{

Intersection intersection ;

intersection.type_ = Intersection::Type::Line ;

intersection.composite_ = Composite { aLine } ;

return intersection ;

}

Intersection Intersection::Ray ( const objects::Ray& aRay )
{

Intersection intersection ;

intersection.type_ = Intersection::Type::Ray ;

intersection.composite_ = Composite { aRay } ;

return intersection ;

}

Intersection Intersection::Segment ( const objects::Segment& aSegment )
{

Intersection intersection ;

intersection.type_ = Intersection::Type::Segment ;

intersection.composite_ = Composite { aSegment } ;

return intersection ;

}

String Intersection::StringFromType ( const Intersection::Type& aType )
{

Expand Down
Loading

0 comments on commit 57c72a9

Please sign in to comment.