Created
March 29, 2020 22:31
-
-
Save sixteenmillimeter/839c16d39d26d04154f52b3f3ee6ee78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SPIRALROTATION=720; | |
SPIRALSTEPS=20; | |
INITIALRADIUS=20; | |
PITCH=6; | |
XMAXSHAPE=2; | |
module ShapeToExtrude () | |
{ | |
// Build in +x space. The outside edge of this shape must follow the extrusion path, or there will be open seams.. | |
polygon ( points= [ | |
[0,-2], | |
[0,2], | |
[1,2], | |
[2,-2] | |
]); | |
} | |
module InwardSpiral (StepSize, Steps, StartRadius, Pitch, ShapeX) { | |
for (i=[0 : Steps - 1]) { | |
// This could be made more computationally efficient | |
// by collapsing intermediate values and by doing only | |
// essential calculations inside the loop, but for now | |
// let's just leave it easy to read. | |
ThisTheta = StepSize * i; | |
NextTheta = StepSize * (i + 1); | |
ThisRadius = StartRadius - i * (Pitch * (StepSize / 360)); | |
// Spiral step approximated by arc of radius ThisRadius, | |
// passing through the start and end points calculated here. | |
NextRadius = StartRadius - (i + 1) * (Pitch * (StepSize / 360)); | |
ThisX = ThisRadius * sin(ThisTheta); | |
ThisY = ThisRadius * cos(ThisTheta); | |
NextX = NextRadius * sin(NextTheta); | |
NextY = NextRadius * cos(NextTheta); | |
DeltaX = NextX - ThisX; | |
DeltaY = NextY - ThisY; | |
SlopeToNext = DeltaY / DeltaX; | |
BisecSlope = -1 / SlopeToNext; | |
ThisXYToBisector = sqrt(DeltaX * DeltaX + DeltaY * DeltaY) / 2; | |
BisectX = ThisX + (DeltaX / 2); | |
BisectY = ThisY + (DeltaY / 2); | |
BisectToCentre = sqrt(pow(ThisRadius, 2) - pow(ThisXYToBisector, 2)); | |
AbsXComponent = sqrt(pow(BisectToCentre, 2) / ( 1 + pow(BisecSlope, 2))); | |
XComponent = NextY < ThisY ? AbsXComponent: -AbsXComponent; | |
YComponent = XComponent * BisecSlope; | |
CentreX = BisectX - XComponent; | |
CentreY = BisectY - YComponent; | |
ExtrudeAngle = -2 * acos(BisectToCentre / ThisRadius); | |
ArcOrientation = NextY < ThisY ? atan(BisecSlope) - (ExtrudeAngle / 2) : -180 + atan(BisecSlope) -(ExtrudeAngle / 2); | |
translate([CentreX, CentreY, 0]) { | |
rotate ([0, 0, ArcOrientation]) { | |
rotate_extrude (angle=ExtrudeAngle, $fn=90) translate ([ThisRadius - ShapeX, 0, 0]) ShapeToExtrude(); | |
} | |
} | |
} | |
} | |
// Main | |
InwardSpiral ( | |
SPIRALROTATION/SPIRALSTEPS, | |
SPIRALSTEPS, | |
INITIALRADIUS, | |
PITCH, | |
XMAXSHAPE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment