mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Fix computation of normals for Surface
This commit is contained in:
parent
d44e248277
commit
4ce8a3ba9d
1 changed files with 18 additions and 10 deletions
|
@ -133,20 +133,28 @@ class Surface(Mobject):
|
||||||
if len(indices) == 0:
|
if len(indices) == 0:
|
||||||
return np.zeros((3, 0))
|
return np.zeros((3, 0))
|
||||||
|
|
||||||
left = indices - 1
|
# For each point, find two adjacent points at indices
|
||||||
right = indices + 1
|
# step1 and step2, such that crossing points[step1] - points
|
||||||
up = indices - nv
|
# with points[step1] - points gives a normal vector
|
||||||
down = indices + nv
|
step1 = indices + 1
|
||||||
|
step2 = indices + nu
|
||||||
|
|
||||||
left[0] = indices[0]
|
# Right edge
|
||||||
right[-1] = indices[-1]
|
step1[nu - 1::nu] = indices[nu - 1::nu] + nu
|
||||||
up[:nv] = indices[:nv]
|
step2[nu - 1::nu] = indices[nu - 1::nu] - 1
|
||||||
down[-nv:] = indices[-nv:]
|
|
||||||
|
# Bottom edge
|
||||||
|
step1[-nu:] = indices[-nu:] - nu
|
||||||
|
step2[-nu:] = indices[-nu:] + 1
|
||||||
|
|
||||||
|
# Lower right point
|
||||||
|
step1[-1] = indices[-1] - 1
|
||||||
|
step2[-1] = indices[-1] - nu
|
||||||
|
|
||||||
points = self.get_points()
|
points = self.get_points()
|
||||||
crosses = cross(
|
crosses = cross(
|
||||||
points[right] - points[left],
|
points[step1] - points,
|
||||||
points[up] - points[down],
|
points[step2] - points,
|
||||||
)
|
)
|
||||||
self.data["normal"] = normalize_along_axis(crosses, 1)
|
self.data["normal"] = normalize_along_axis(crosses, 1)
|
||||||
return self.data["normal"]
|
return self.data["normal"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue