From 19a0a725459a2679b6e7392350f771e04813528f Mon Sep 17 00:00:00 2001 From: Solara570 Date: Wed, 20 Dec 2017 20:31:02 +0800 Subject: [PATCH] 3D Hilbert Curve Implemented --- topics/fractals.py | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/topics/fractals.py b/topics/fractals.py index 93825822..7a43ffab 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 = {