genepy3d_gpl.interact package#

Module contents#

Submodules#

genepy3d_gpl.interact.curvesurface module#

Interaction between Curve and Surface objects.

Functions:

intersect(crv, surf)

Intersection between curve and surface, using AABB_tree_Triangle_3_soup from CGAL as exposed by CGAL-swig-bindings.

inonout(crv, surf)

Classify curve segments as being inside/lying on/outside of the surface.

genepy3d_gpl.interact.curvesurface.intersect(crv, surf)[source]#

Intersection between curve and surface, using AABB_tree_Triangle_3_soup from CGAL as exposed by CGAL-swig-bindings.

Parameters:
  • crv (Curve) – Curve object.

  • surf (Surface) – Surface object.

Returns:

List of intersected points and their corresponding curve segments.

Examples

import numpy as np
from genepy3d.obj.curves import Curve
from genepy3d.obj.surfaces import Surface
from genepy3d_gpl.interact import curvesurface
import matplotlib.pyplot as plt

# Create a box
coors = np.array([[0.,0.,0.],[0.,1.,0.],[0.,1.,1.],[0.,0.,1.],[1.,0.,0.],[1.,1.,0.],[1.,1.,1.],[1.,0.,1.]])
srf = Surface.from_points_qhull(coors)

# Create a curve
coors = np.array([[-1.5,0.5,0.5],[0,0.5,0.5],[1.5,0.5,0.5]])
crv = Curve(coors)

pnts, _ = curvesurface.intersect(crv,srf)

# Plot
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
srf.plot(ax)
crv.plot(ax,show_root=False)
pnts.plot(ax,point_args={"color":"r"});
genepy3d_gpl.interact.curvesurface.inonout(crv, surf)[source]#

Classify curve segments as being inside/lying on/outside of the surface. Use intersect, which uses AABB_tree_Triangle_3_soup from CGAL as exposed by CGAL-swig-bindings.

Parameters:
  • crv (Curve) – Curve object.

  • surf (Surface) – Surface object.

Returns:

List of curves that are inside, onside and outside of the surface.

Notes

The surface must be watertight.

Examples

import numpy as np
from genepy3d.obj.curves import Curve
from genepy3d.obj.surfaces import Surface
from genepy3d_gpl.interact import curvesurface
import matplotlib.pyplot as plt

# Create a box
coors = np.array([[0.,0.,0.],[0.,1.,0.],[0.,1.,1.],[0.,0.,1.],[1.,0.,0.],[1.,1.,0.],[1.,1.,1.],[1.,0.,1.]])
srf = Surface.from_points_qhull(coors)

print("Surface is watertight?",srf.is_watertight)

# Create a curve
coors = np.array([[-1.5,0.5,0.5],[0,0.5,0.5],[1.,1.,1.],[1.,0.5,0.5],[1.5,0.5,0.5]])
crv = Curve(coors)

# Compute curve segments lying inside/on/outside of the surface
crvin, crvon, crvout = curvesurface.inonout(crv,srf)

# Plot
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
srf.plot(ax)

# Curve segments inside the surface
for tmp in crvin:
    tmp.plot(ax,show_root=False,line_args={"color":"r"})

# Curve segments lying on the surface
for tmp in crvon:
    tmp.plot(ax,show_root=False,line_args={"color":"g"})

# Curve segments outside the surface
for tmp in crvout:
    tmp.plot(ax,show_root=False,line_args={"color":"b"})

genepy3d_gpl.interact.pointsurface module#

Interaction between Points and Surface objects.

Functions:

inonout(pnts, surf[, extreme_coors, ...])

Check points inside, lying on or outside of the surface.

genepy3d_gpl.interact.pointsurface.inonout(pnts, surf, extreme_coors=None, return_masks=False)[source]#

Check points inside, lying on or outside of the surface.

We used ray casting algorithm described here [1].

Parameters:
  • pnts (Points) – points object.

  • surf (Surface) – surface object.

  • extreme_coors (array) – coordinate used to create a ray line from this coordinate to a point from the points cloud. If None, it is computed automatically.

Returns:

if return_masks is True, then return the three bool arrays marking points inside/lying on/outside of the surface. Else return three Points objects for inside, onside and outside of the surface.

Notes

The surface must be watertight.

References

Examples

import numpy as np
from genepy3d.obj.points import Points
from genepy3d.obj.surfaces import Surface
from genepy3d_gpl.interact import pointsurface
import matplotlib.pyplot as plt

# Create a box
coors = np.array([[0.,0.,0.],[0.,1.,0.],[0.,1.,1.],[0.,0.,1.],[1.,0.,0.],[1.,1.,0.],[1.,1.,1.],[1.,0.,1.]])
srf = Surface.from_points_qhull(coors)

print("Surface is watertight?",srf.is_watertight)

# Create a points cloud
coors = np.array([[-1.5,0.5,0.5],[0,0.5,0.5],[0.5,0.5,0.5],[1.,1.,1.],[1.,0.5,0.5],[1.5,0.5,0.5]])
pnts = Points(coors)

# Compute points lying inside/on/outside of the surface
pntin, pnton, pntout = pointsurface.inonout(pnts,srf)

# Plot
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
srf.plot(ax)
pntin.plot(ax,point_args={"color":"r"})
pnton.plot(ax,point_args={"color":"g"})
pntout.plot(ax,point_args={"color":"b"})