Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Plane.polyline_xsection: Add ret_edge_indices param (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow authored Jan 31, 2019
1 parent dd390d5 commit 9116f49
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions blmath/geometry/primitives/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,10 @@ def project_point(self, point):
signed_distance_to_point = self.signed_distance(point.reshape((-1, 3)))[0]
return point - signed_distance_to_point * self._n

def polyline_xsection(self, polyline):
def polyline_xsection(self, polyline, ret_edge_indices=False):
'''
Returns the points of intersection between the plane and any of the
edges of `polyline`, which should be an instance of Polyline.
'''
# Identify edges with endpoints that are not on the same side of the plane
sgn_dists = self.signed_distance(polyline.v)
Expand All @@ -206,8 +205,10 @@ def polyline_xsection(self, polyline):
t = endpoint_distances / endpoint_distances.sum(axis=1)[:, np.newaxis]
# Take a weighted average of the endpoints to obtain the points of intersection
intersection_points = ((1. - t[:, :, np.newaxis]) * polyline.v[polyline.e[which_es]]).sum(axis=1)
#assert(np.all(self.distance(intersection_points) < 1e-10))
return intersection_points
if ret_edge_indices:
return intersection_points, which_es.nonzero()[0]
else:
return intersection_points

def line_xsection(self, pt, ray):
return self._line_xsection(np.asarray(pt).ravel(), np.asarray(ray).ravel())
Expand Down

0 comments on commit 9116f49

Please sign in to comment.