|
|
|
$fn=25; |
|
|
|
|
|
module DrawBallPattern (SphereDiameter, DistanceFactor, BottomOuterPitchDiameter, BottomInnerPitchDiameter, TopOuterPitchDiameter, TopInnerPitchDiameter, PitchHeight, MyColor) |
|
{ |
|
|
|
//****************** intermediate variables ****************************** |
|
|
|
BottomOuterPitchRadius = BottomOuterPitchDiameter/2 ; |
|
BottomInnerPitchRadius = BottomInnerPitchDiameter/2 ; |
|
|
|
//radius of sphere (r) |
|
SphereRadius = SphereDiameter/2 ; |
|
|
|
//Distance between the outsides of two spheres |
|
OutsideSeparationDistance = DistanceFactor * SphereRadius; |
|
|
|
//Heart to heart distance between two spheres |
|
HeartToHeartDistance = SphereDiameter + OutsideSeparationDistance ; |
|
|
|
//Nr of spheres wthin the ring |
|
A=BottomOuterPitchRadius-BottomInnerPitchRadius-2*OutsideSeparationDistance; |
|
B=HeartToHeartDistance; |
|
NrOfRings = floor(A/B); |
|
|
|
|
|
//The Nr. of rings that fit in the given PitchHeight |
|
NrOfRows = floor((PitchHeight-2*OutsideSeparationDistance)/HeartToHeartDistance) ; |
|
|
|
//The remaining height as we only allow an integer number of spheres which won't fit exactly in Height |
|
Hoogte = 2*SphereRadius + (NrOfRows-1) * HeartToHeartDistance ; |
|
RestHoogte = PitchHeight - Hoogte ; |
|
|
|
|
|
|
|
//******************* Export some intermediate results *************************** |
|
|
|
echo("**************************************") ; |
|
echo("OutsideSeparationDistance=",OutsideSeparationDistance) ; |
|
echo("HeartToHeartDistance=",HeartToHeartDistance) ; |
|
echo("NrRows=",NrOfRows) ; |
|
echo("NrRings=",NrOfRings) ; |
|
echo("RestHoogte=",RestHoogte) ; |
|
echo("**************************************") ; |
|
|
|
|
|
//******************* DRAW SPHERE RING PATTERN *************************** |
|
|
|
for (r = [0 : 1 : NrOfRings-1]) { |
|
PitchRadius = BottomOuterPitchRadius - SphereRadius - (BottomOuterPitchRadius - BottomInnerPitchRadius) * r/(NrOfRings) ; |
|
NrBalls = floor(2*PI*PitchRadius/HeartToHeartDistance) ; |
|
echo ("ring ", r, ": ", NrBalls, " balls") ; |
|
for (h = [1 : 1 : NrOfRows]) { |
|
for (a = [1 : 1 : NrBalls]) { |
|
rotate([0, 0, (a * 360/NrBalls)]){ |
|
translate([PitchRadius, 0, RestHoogte/2 + SphereRadius + (h-1)*HeartToHeartDistance]){ |
|
color(MyColor) sphere(r=SphereRadius); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} //End of mocule |
|
|
|
//************** MAIN CALCULATION PARAMETERS ******************** |
|
SphereDiameter = 12 ; //Diameter of the spheres |
|
DistanceFactor = 0.0813 ; //Fraction of the sphere diameter that the sprehes are separates from each other |
|
BottomOuterPitchDiameter = 150; //de diameter van onderste buitenste cirkel waarbinnen de bolletjes kunnen liggen |
|
BottomInnerPitchDiameter = 120 ; //de diameter van onderste binnenste cirkel waarbinnen de balletjes kunnen liggen (r1) |
|
TopOuterPitchDiameter = 100; //de diameter van bovenste buitenste cirkel waarbinnen de bolletjes kunnen liggen |
|
TopInnerPitchDiameter = 60 ; //de diameter van bovenste binnenste cirkel waarbinnen de balletjes kunnen liggen |
|
PitchHeight = 255 ; //De hoogte waarbinnen de balletjes kunnen liggen (H) |
|
cBallColor = "Blue"; |
|
cCubeColor = "Red" ; |
|
CubeSize = [200,48,244]; //The intersection cube |
|
CubePosition = [-100,0,6] ; //Translation vector of intersection cube |
|
DrawIntersection = true ; //if true, the intersection is drawn. If false, the union is drawn |
|
|
|
|
|
//Draw intersection or union by calling the module |
|
if (DrawIntersection) { |
|
intersection(){ |
|
color (cBallColor) DrawBallPattern (SphereDiameter, DistanceFactor, BottomOuterPitchDiameter, BottomInnerPitchDiameter, TopOuterPitchDiameter, TopInnerPitchDiameter, PitchHeight, cBallColor); |
|
translate (CubePosition) color ("red") cube (CubeSize, false); |
|
} |
|
} |
|
else { |
|
color (cBallColor) DrawBallPattern (SphereDiameter, DistanceFactor, BottomOuterPitchDiameter, BottomInnerPitchDiameter, TopOuterPitchDiameter, TopInnerPitchDiameter, PitchHeight, cBallColor); |
|
translate (CubePosition) color ("red") cube (CubeSize, false); |
|
} |