Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

3D Hilbert Curve Implemented

Solara57019a0a725459a
diff --git a/topics/fractals.py b/topics/fractals.py
index 938258225..7a43ffaba 100644
--- a/topics/fractals.py
+++ b/topics/fractals.py
@@ -423,18 +423,39 @@ class HilbertCurve(SelfSimilarSpaceFillingCurve):
class HilbertCurve3D(SelfSimilarSpaceFillingCurve):
CONFIG = {
- "offsets" : [
- LEFT+DOWN+OUT,
- LEFT+UP+OUT,
- LEFT+UP+IN,
- LEFT+DOWN+IN,
- RIGHT+DOWN+IN,
- RIGHT+UP+IN,
- RIGHT+UP+OUT,
- RIGHT+DOWN+OUT,
+ "offsets" : [
+ RIGHT+DOWN+IN,
+ LEFT+DOWN+IN,
+ LEFT+DOWN+OUT,
+ RIGHT+DOWN+OUT,
+ RIGHT+UP+OUT,
+ LEFT+UP+OUT,
+ LEFT+UP+IN,
+ RIGHT+UP+IN,
],
- "offset_to_rotation_axis" : {}#TODO
+ "offset_to_rotation_axis_and_angle" : {
+ str(RIGHT+DOWN+IN) : (LEFT+UP+OUT , 2*np.pi/3),
+ str(LEFT+DOWN+IN) : (RIGHT+DOWN+IN, 2*np.pi/3),
+ str(LEFT+DOWN+OUT) : (RIGHT+DOWN+IN, 2*np.pi/3),
+ str(RIGHT+DOWN+OUT) : (UP , np.pi ),
+ str(RIGHT+UP+OUT) : (UP , np.pi ),
+ str(LEFT+UP+OUT) : (LEFT+DOWN+OUT, 2*np.pi/3),
+ str(LEFT+UP+IN) : (LEFT+DOWN+OUT, 2*np.pi/3),
+ str(RIGHT+UP+IN) : (RIGHT+UP+IN , 2*np.pi/3),
+ },
}
+ # Rewrote transform method to include the rotation angle
+ def transform(self, points, offset):
+ copy = np.array(points)
+ copy = rotate(
+ copy,
+ axis = self.offset_to_rotation_axis_and_angle[str(offset)][0],
+ angle = self.offset_to_rotation_axis_and_angle[str(offset)][1],
+ )
+ copy /= self.scale_factor,
+ copy += offset*self.radius*self.radius_scale_factor
+ return copy
+
class PeanoCurve(SelfSimilarSpaceFillingCurve):
CONFIG = {