Merge pull request #273 from 3b1b/quaternions

Quaternions
This commit is contained in:
Grant Sanderson 2018-08-22 21:24:09 -07:00 committed by GitHub
commit ce06e58505
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 9 deletions

View file

@ -547,7 +547,7 @@ class Camera(object):
points[violator_indices] = rescaled
return points
def transform_points_pre_display(self, points, mobject):
def transform_points_pre_display(self, mobject, points):
# Subclasses (like ThreeDCamera) may want to
# adjust points before they're shown
return points

View file

@ -17,6 +17,7 @@ from utils.color import get_shaded_rgb
from utils.space_ops import rotation_about_z
from utils.space_ops import rotation_matrix
from utils.space_ops import center_of_mass
from utils.simple_functions import fdiv
class ThreeDCamera(Camera):
@ -166,9 +167,15 @@ class ThreeDCamera(Camera):
points -= frame_center
points = np.dot(points, rot_matrix.T)
zs = points[:, 2]
zs[zs >= distance] = distance - 0.001
for i in 0, 1:
points[:, i] *= distance / (distance - zs)
# Proper projedtion would involve multiplying
# x and y by d / (d-z). But for points with high
# z value, this causes weird artifacts, and applying
# the exponential helps smooth it out.
factor = np.exp(zs / distance)
lt0 = zs < 0
factor[lt0] = (distance / (distance - zs[lt0]))
points[:, i] *= factor
points += frame_center
return points

View file

@ -35,7 +35,7 @@ def get_3d_vmob_end_corner(vmob):
def get_3d_vmob_unit_normal(vmob, point_index):
n_points = vmob.get_num_points()
if vmob.get_num_points() == 0:
if len(vmob.get_anchors()) <= 2:
return np.array(UP)
i = point_index
im1 = i - 1 if i > 0 else (n_points - 2)

View file

@ -96,7 +96,7 @@ class ParametricSurface(VGroup):
class Sphere(ParametricSurface):
CONFIG = {
"resolution": (12, 24),
"radius": 3,
"radius": 1,
"u_min": 0.001,
"u_max": PI - 0.001,
"v_min": 0,
@ -128,8 +128,9 @@ class Cube(VGroup):
def generate_points(self):
for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
face = ThreeDVMobject(
Square(side_length=self.side_length)
face = Square(
side_length=self.side_length,
shade_in_3d=True,
)
face.make_jagged()
face.flip()

View file

@ -53,7 +53,6 @@ def digest_config(obj, kwargs, caller_locals={}):
caller_locals = filtered_locals(caller_locals)
all_dicts = [kwargs, caller_locals, obj.__dict__]
all_dicts += static_configs
all_new_dicts = [kwargs, caller_locals] + static_configs
obj.__dict__ = merge_config(all_dicts)
@ -62,7 +61,7 @@ def merge_config(all_dicts):
config = dict()
for c in all_config:
key, value = c
if not key in config:
if key not in config:
config[key] = value
else:
# When two dictionaries have the same key, they are merged.