XM Magdalena 3D print, GGeorgy (3D)
LC #42 Pipers Alley

View Full Version : fibonacci / golden ratio

01-27-2009, 06:10 PM
Hey there,

I'm trying to show the fibonacci spiral onto the viewport but I don't get it.
I handled to display something on the screen but not a spiral...

fibonacci_array = #()

gw.setColor #line yellow
for i = 1 to 22 do
x = 1.618*i
y = -0.618^-i
--m = ((x-y)/2.2361)
append fibonacci_array ([x,y,0])
gw.wPolyline fibonacci_array false

gw.wText ([4,30,0]) "fibonacci spiral" color:yellow

gw.enlargeUpdateRect #whole

Thank You!

01-27-2009, 09:15 PM
that's because you're not actually drawing a spiral, near's I can tell.

myShape = splineshape()
addNewSpline myShape
for p in fibonacci_array do ( addKnot myShape 1 #corner #line p )
updateShape myShape
myShape.vertexTicks = true

Might want to review your code for generating the spiral - if nothing else, the X coordinate shouldn't be a linear progression :)

01-27-2009, 09:42 PM
Thanks for your answer but I need to display this kind of spiral in the view-/cameraport
like this one (http://www.learncpp.com/images/CppTutorial/Section7/Fibonacci.png)

Exactly like in this image with rectangles and this spiral...

I started now to make the rectangles "hardcoded" but there must be a formula for this, too... did not find an answer, yet...

maxWidth = gw.getWinSizeX()
maxHeight = gw.getWinSizeY()

gw.setColor #line orange
gw.wPolyline #([0,0,0],[maxWidth*0.618,0,0],[maxWidth*0.618,maxHeight-1,0],[0,maxHeight-1,0]) true
gw.wPolyline #([maxWidth*0.618,0,0],[maxWidth-1,0,0],[maxWidth-1,maxHeight*0.618,0],[maxWidth*0.618,maxHeight*0.618,0]) true

01-27-2009, 09:47 PM
adding this line
gw.setColor #line red
gw.wPolyline #([maxWidth-1,maxHeight*0.618,0],[maxWidth-1,maxHeight-1,0],[maxWidth-((maxWidth-(maxWidth*0.618))*0.618),maxHeight-1,0],[maxWidth-((maxWidth-(maxWidth*0.618))*0.618),maxHeight*0.618,0]) true
makes the next rectangle (number 55 on the image)

I'm not good at math so I can't see a formula... :cry:

01-27-2009, 11:07 PM
I wrote a script about the rectangles of a Fibonacci Spiral (not golden ration though...) on |[Pixelplausch.de]| (http://www.pixelplausch.de/autodesk-3ds-max/2658-maxscript-variabel-loop-deklarieren.html) . Maybe it helps you..

01-27-2009, 11:55 PM
you might find this useful too -


01-28-2009, 10:48 AM
Hey, thank you all!
I hope that helps.


01-28-2009, 03:50 PM
I came out with this after trying the link from Piflik. It seems to work in one way or another but for displaying it on the screen/viewport it should be kind of reversed to split the screen like on this image (http://www.learncpp.com/images/CppTutorial/Section7/Fibonacci.png). Any ideas on how to reverse this??

After this change there still is the problem with the spiral but there doesn't seem to be code for this, no curves just polygons and polylines...?

global fibonacci_array = #()

--maxWidth = gw.getWinSizeX()
--maxHeight = gw.getWinSizeY()

global w = 15
global pos_Alt =[0,1,0] -- old position

fn drawQuad x y w h =
gw.wPolyline #([x,y,0],[x+w,y,0],[x+w,y+h,0],[x,y+h,0]) true

fibonacci_array[1] = 1 -- first 2 fibonacci numbers
fibonacci_array[2] = 1

gw.setColor #line orange
gw.wText ([4,30,0]) "fibonacci spiral" color:orange

drawQuad 0 0 1 1
drawQuad 1 0 1 1

for i = 3 to 12 do
fibonacci_array[i] = fibonacci_array[i-1] + fibonacci_array[i-2]

if i < w then
a = fibonacci_array[i]/2 as float
b = fibonacci_array[i-1]/2 as float
c = fibonacci_array[i-2]/2 as float

case of
(mod i 4 == 3): pos_Neu = [a+b,-1*c,0]
(mod i 4 == 0): pos_Neu = [-1*c,-1*(a+b),0]
(mod i 4 == 1): pos_Neu = [-1*(a+b),c,0]
(mod i 4 == 2): pos_Neu = [c,a+b,0]
position = pos_Alt + pos_Neu
drawQuad position.x position.y fibonacci_array[i] fibonacci_array[i]
pos_Alt = position


gw.enlargeUpdateRect #whole

CGTalk Moderation
01-28-2009, 03:50 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.