Skip to content

Commit

Permalink
fix shapes.Plane.normal in #1159
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomusy committed Jul 23, 2024
1 parent edfeb4e commit 7b4e124
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
- fix Volume masking in #1146 by @ivishalanand
- fix `LegendBox` in #1153 by @GerritFischer
- add `mesh.laplacian_diffusion()`
- fix DistanceTool in #1158
- fix `DistanceTool` in #1158
- fix `shapes.Plane.normal` in #1159 by @smoothumut




## Soft-breaking Changes
Changes that will break existing code whose fixing is trivial:

- None


## Hard-breaking Changes
Expand Down
21 changes: 17 additions & 4 deletions vedo/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3041,11 +3041,24 @@ def clone(self, deep=True) -> "Plane":
@property
def normal(self) -> np.ndarray:
pts = self.vertices
AB = pts[1] - pts[0]
AC = pts[2] - pts[0]
# this is necessary because plane can have high resolution
# p0, p1 = pts[0], pts[1]
# AB = p1 - p0
# AB /= np.linalg.norm(AB)
# for pt in pts[2:]:
# AC = pt - p0
# AC /= np.linalg.norm(AC)
# cosine_angle = np.dot(AB, AC)
# if abs(cosine_angle) < 0.99:
# normal = np.cross(AB, AC)
# return normal / np.linalg.norm(normal)
p0, p1, p2 = pts[0], pts[1], pts[int(len(pts)/2 +0.5)]
AB = p1 - p0
AB /= np.linalg.norm(AB)
AC = p2 - p0
AC /= np.linalg.norm(AC)
normal = np.cross(AB, AC)
normal = normal / np.linalg.norm(normal)
return normal
return normal / np.linalg.norm(normal)

@property
def center(self) -> np.ndarray:
Expand Down

0 comments on commit 7b4e124

Please sign in to comment.