HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How would I remedy this hyperbolic paradox

04-16-2004, 05:18 AM#1
Narwanza
I create a simple spiral function using the polar equation of r = t. I now face a problem though. I was going to use it for several effects but I am using a variation of theta to come up with each point. So insted of the locations being equidistant from each other they slowly get farther and farther apart. Most of you know what I am saying, but look at this drawing anyway.

Code:
                        /\
                       /  \
                      /    \
As you can see, two points, one placed on each leg, would increase in distance from each other. How could I make it so that it would calculate points based on how far away it is from the other one and still be on the spiral? I can think of a few ways to do it but they are too processing heavy to even think about using in a practical application. Could somone who actually has worked with stuff like this b4 help me?

Here is the function if you want to look at what I have done so far. Right now I am using the flags as a debugging method to see how things are coming along. Later I am going to put it on a timer to create spiral effects.

Code:
function SpiralTemp takes location origin, real radius, real degInc,real spiralSize returns nothing
	local location temp = null
	local real R = 0
	local real theta = 0
	loop
		exitwhen RAbsBJ((R*Cos(Deg2Rad(theta)))+GetLocationX(origin)) > radius or RAbsBJ((R*Sin(Deg2Rad(theta)))+GetLocationY(origin)) > radius
		set R = theta*spiralSize
		set temp = Location((R*Cos(Deg2Rad(theta)))+GetLocationX(origin),(R*Sin(Deg2Rad(theta)))+GetLocationY(origin))
		call AddSpecialEffectLoc("Doodads\\LordaeronSummer\\Props\\BannerHuman\\BannerHuman0.mdx",temp)
		set theta = (theta + degInc)
		call RemoveLocation(temp)
	endloop
	set temp = null
endfunction

Brief explanation:
It asks for a radius which is the radius of the circle in which the spiral is contained, as soon as one of the x or y values of the location leaves the circle it stops running. Theta is determined by the degInc (degree increment) passed. The rest you should be able to understand.
04-16-2004, 06:51 PM#2
AIAndy
Funny, I already put that answer in the other thread and now I see here that you ask for it. Look at the spiral template in my spell classes system (http://kattana.users.whitehat.dk/viewfunc.php?id=274).
04-18-2004, 07:05 PM#3
Narwanza
Could you walk me through your equation Andy? I can't figure it out just by looking at the code.
04-18-2004, 09:42 PM#4
AIAndy
Do you want an explanation on how you get to that equation or just an explanation on how to use it ?
04-18-2004, 10:35 PM#5
Narwanza
Explanation on how to get it. For some reason I like to be able to completly understand other people's code before I use it. That is the only reason I know anything about how to do this stuff (haven't been taught it yet in school) is because I read and learn how to do things. In fact, I will spend hours trying to understand how someone created a function by making my own recreation. This is how I have learned JASS as well as I have in less than a month. As you can see also, programming in optimized form is hard to understand. Let me give you this example of another function I am working on. (not finished yet, still has some bugs)

Optimizied form:
Code:
function LocationToLocationByAngle takes location l, real angle returns location
    return Location(SquareRoot(GetLocationX(l)*GetLocationX(l)+GetLocationY(l)*GetLocationY(l))*CosBJ(AtanBJ(GetLocationY(l)/GetLocationX(l)) + angle),SquareRoot(GetLocationX(l)*GetLocationX(l)+GetLocationY(l)*GetLocationY(l))*SinBJ(AtanBJ(GetLocationY(l)/GetLocationX(l)) + angle))
endfunction
Easier to understand form:
Code:
function LocationToLocationByAngle takes location l, real angle returns location
    local real R = SquareRoot(GetLocationX(l)*GetLocationX(l)+GetLocationY(l)*GetLocationY(l))
    local real theta = AtanBJ(GetLocationY(l)/GetLocationX(l))
    return Location(R*CosBJ(theta+angle),R*SinBJ(theta + angle))
endfunction

The first one is all in one line making it "optimized" (well, not really because It has to compute things twice, but you get the picture). The second one shows that it converts it to polar, and then back to cartesian with the added theta. So, could I get an explanation?
04-19-2004, 06:30 AM#6
AIAndy
I'll give you the explanation when I get back this evening.
04-19-2004, 08:20 PM#7
AIAndy
The formula works with polar projection. So the variables are angle and radius.
Angle is the variable that determines where in the spiral we are.
As parameters of the spiral there is the point distance and the arc distance (the distance that the spiral will be further away from the center on 360 degrees further).
Radius can be computed from angle with:
radius = angle * arc distance / (2 * pi)

Now the new angle needs to be computed so that the point distance is kept. So we have a current angle and we want to compute the next angle.
The point distance that we want is a certain arc length of the spiral. The arc length of the spiral between the old angle and the new one is the same as the arc length of the circle that has the average radius between old and new point.

So that is now put into a formula:
point distance = (new_angle - c_angle) * (new_radius + c_radius) / 2

Now enter the radius formula from above for new_radius and c_radius and you will get an equation where the only unknown value is new_angle. If I did not make a mistake it should be a quadratic equation which you can solve and you should get the formula like in my spiral template (only enhanced by start_angle and direction).