Spiral-Problem
Blitz3D Forums/Blitz3D Programming/Spiral-Problem
| ||
| Hi! First of all: Since I'm no native speaker - please excuse my english. So here's my problem: Imagine a spiral which takes 3 "turns". This spiral consists of let's say at least 10000 positions starting from the origin. The problem each position should have the same distance to the next one. Now I could go and put the coordinates in an array like this: dim px#(99999),py#(99999) spiralturns=3 for i#=0 to 360*spiralturns step 0.0001 x#=cos(i#)*i# y#=sin(i#)*i# if sqr((x#-xa#)^2+(y#-ya#)^2) >= distance n=n+1 px#(n)=x# py#(n)=y# xa#=x# ya#=y endif next But that's not what I want. I wanna have a (well two - one for x and one for y) formula. Input=Number of positon > Output = x,y. Second idea: A logarithmic way like: x#=cos(log(n#)*500)*n# y#=sin(log(n#)*500)*n# The problem here: That's not a "normal" sprial, since the distance between each "circles" or "round" increases... So here I am and I need help. Thanks! |
| ||
| I'm guessing this is in 2d. I'm pretty sure i know how to solve it, but could you privde the code you using to draw the spiral? |
| ||
| Well, I dont have a clue on how to do what you want to accomplish...but wouldn the program be slow as heck with all that math (and huge arrays) bein' calculated on the fly? |
| ||
how about this:dim px#(99999),py#(99999) spiralturns=3 stepvalue# = (spiralturns * 360) / 1000 for i=0 to 1000 x#=cos(i * stepvalue)*(i * stepvalue) y#=sin(i * stepvalue)*(i * stepvalue) px#(i)=x# py#(i)=y# next I think the problem was that for/next step value of .0001...Blitz needs to allow for/next steps to use valriables instead of constants :P |
| ||
| Well, thanks... but... My code works fine the way it is. It's got nothing to do with Blitz but just with maths... |
| ||
| Maybe I should describe my problem in other words: Imagine a spiral with 3 coplete turns and a radius of 100 meters. Put it on a x/y-system with the origin 0.00,0.00. No walk 300 meters from the start (origin). Where are you (x/y)? |
| ||
| I know what your asking. Can you post the code you use for working out and drawing the spiral. :) |
| ||
| Sure... The initial attempt (with unequal distances): For i=0 To 1080 Step 10 Plot Cos(i)*i/10+160,Sin(i)*i/10+120 Next While Not MouseDown(1):Wend The logaritmic one (equal distances, but the spiral gets wider...): For i=0 To 1080 Step 10 Plot Cos(Log(i)*1000)*i/10+160,Sin(Log(i)*1000)*i/10+120 Next While Not MouseDown(1):Wend The array-solution is mentioned above. But I don't want and array-solution... |
| ||
| nearly got it |
| ||
| Ok, i think this is what you want? Press 1 to enter a position. Then press enter. Repeat as many times as you want.
Graphics 800,600
SetBuffer BackBuffer()
no=-1
While Not KeyHit(1)
Cls
For i=0 To 1080 Step 10
Plot Cos(i)*i/10+160,Sin(i)*i/10+120
Next
If KeyHit(2) Then
FlushKeys()
no=Input("Enter position:")
FlushKeys()
End If
If no>-1 Then
Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
Rect Cos(no)*no/10+160,Sin(no)*no/10+120,2,2
Color 255,255,255
End If
If no>-1 Then
Text 200,0," x = "+(Cos(no)*no/10+160)+" y = "+(Sin(no)*no/10+120)
End If
Flip
Wend
|
| ||
| Thank you! But unfortunately it's not what I am looking for since it's just my function vice versa... But the function itself is wrong for what I need. The dots in the spiral should have the same distance. Meaning sqr((x2-x1)^2+(y2-y1)^2) should be the same for every two neighbor-dots... That's what the array-routine is doing. But there has to be another way. |
| ||
| Probably by making the angle smaller as the spiral goes out is the way to go. I'm going to sleep right now, but i'll try something quickly :) |
| ||
| Mmm... the problem is the step part of the loop has to be a constant. If it were changable, it shouldn't be a problem.... |
| ||
Ok man, just tweak the number that i've marked with stars. Don't go below 0.97 tho.Graphics 800,600 SetBuffer BackBuffer() no=-1 temp#=20 loop#=0 While Not KeyHit(1) Cls loop#=0 temp#=20 Repeat If KeyHit(1) Then End Plot Cos(loop)*loop/10+160,Sin(loop)*loop/10+120 loop=loop+temp temp=temp*0.9855;*******<<<<< tweak spacing. Don't go below 0.97 Until loop>1080 Flip Wend |