mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Allow for specifying true normals and orientation of Sphere
This commit is contained in:
parent
46c898977a
commit
054865569e
1 changed files with 8 additions and 3 deletions
|
@ -97,9 +97,12 @@ class Sphere(Surface):
|
|||
v_range: Tuple[float, float] = (0, PI),
|
||||
resolution: Tuple[int, int] = (101, 51),
|
||||
radius: float = 1.0,
|
||||
true_normals: bool = True,
|
||||
clockwise=False,
|
||||
**kwargs,
|
||||
):
|
||||
self.radius = radius
|
||||
self.clockwise = clockwise
|
||||
super().__init__(
|
||||
u_range=u_range,
|
||||
v_range=v_range,
|
||||
|
@ -107,12 +110,14 @@ class Sphere(Surface):
|
|||
**kwargs
|
||||
)
|
||||
# Add bespoke normal specification to avoid issue at poles
|
||||
self.data['d_normal_point'] = self.data['point'] * ((radius + self.normal_nudge) / radius)
|
||||
if true_normals:
|
||||
self.data['d_normal_point'] = self.data['point'] * ((radius + self.normal_nudge) / radius)
|
||||
|
||||
def uv_func(self, u: float, v: float) -> np.ndarray:
|
||||
sign = -1 if self.clockwise else +1
|
||||
return self.radius * np.array([
|
||||
math.cos(u) * math.sin(v),
|
||||
math.sin(u) * math.sin(v),
|
||||
math.cos(sign * u) * math.sin(v),
|
||||
math.sin(sign * u) * math.sin(v),
|
||||
-math.cos(v)
|
||||
])
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue