HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Circular Movement via SetUnitX/Y

11-19-2008, 08:02 PM#1
Zerzax
I'd like to know how people do this with JASS. Now I did figure out on my own that:
If you take a circle with a fixed x and y center that you know, as well as a fixed radius, with x1 and y1 being the center's coordinates:

y2=SquareRoot(Radius^2 + (x2 - x1)^2) + y1

Using the pythagorean theorem. I input an arbitrary x2 and some radius to find the exact y coordinate that together with x2 follows the edge of the circle. However, that requires the use of the SquareRoot function. Do people use this normally? Is this unconventional? And what other ways might it be done?
11-19-2008, 08:33 PM#2
xombie
Think of it as a thread attached to a center point. As you change the angle it will move in a circular fashion, thus...

Collapse JASS:
set x2 = centerX + radius * Cos(angle) //angle in radians
set y2 = centerY + radius * Sin(angle) // angle in radians
set angle = angle + angleIntervals

If you were to increase or decrease the angle would determine whether or not it moved in counter-clockwise or clockwise direction, respectively.

Do you understand?
11-19-2008, 08:37 PM#3
Zerzax
Yep, a projection at that angle that increments. I'm guessing that that would be much less expensive than using the squareroot function. Why didn't I think of that? +rep, and to anyone else who finds yet another solution.

EDIT: The rep popup is just an expanded box, I guess its not loading properly. I'll rep you soon as it works. Thanks again.

I think the reason I hadn't thought of that was because of the thought process I used to derive that pythagorean equation. I had wanted to use GetRandomReal to generate an x value within the circle's radius and then use that value to determine a limited range of y values... Whatever.
11-20-2008, 02:24 AM#4
MaD[Lion]
Sin and Cos in jass eats alot of resource... ive tested this. Squareroot is really fast compared to using Sin & Cos.

but for circular motion u can only use Cos/Sin, unless you use the circular motion formula, where u find a tangent speed tat will give circulation to a given centripental acceleration. Then u dont need to worry about Cos Sin or squareroot at all.

here is a good resource of circular motion formulas:
http://en.wikipedia.org/wiki/Circular_motion

note this does not apply to eclipse motion. Tats when things will becoem complex(for me) :(
11-20-2008, 02:30 AM#5
Zerzax
I see. That sounds pretty cool. Would it be something you could post an example of in this thread? Or is it too complex? Also, I'm taking Precalculus this year, would it be something I would learn in Calculus?
11-20-2008, 02:48 AM#6
Ammorth
Quote:
Originally Posted by MaD[Lion]
Sin and Cos in jass eats alot of resource... ive tested this. Squareroot is really fast compared to using Sin & Cos.

I thought sin and cos were just a fancy table lookup and actually rather fast, compared to a squareroot.

Quote:
Originally Posted by Zerzax
Also, I'm taking Precalculus this year, would it be something I would learn in Calculus?

Calculus (at least first year) will only introduce you to the idea of limits and derivatives. The stuff MadLion is talking about is more physics related than calculus related.
11-20-2008, 03:17 AM#7
Zerzax
Once I started thinking about it, it seemed like a physics idea. I'm not taking physics this year, I stuck with AP Chem this year, though I'm gunning for BC Calc and physics next year.

People seem to be divided on this issue: I've heard from Captain Griffen that the trig functions are very fast and squareroot is cumbersome, while others say that squareroot, as a native, is nothing to worry about. But I would like to find out how to manage doing it without any function calls, regardless of who says what.
11-20-2008, 04:09 AM#8
Jazradel
Collapse JASS:
set x2 = centerX + radius * Cos(angle) //angle in radians
set y2 = centerY + radius * Sin(angle) // angle in radians
set angle = angle + angleIntervals
That's the fastest your going to get.

Trig functions are a table lookup, and are implemented in c so they're very fast.
11-20-2008, 06:19 AM#9
grim001
Whether or not Sin/Cos/SquareRoot are "fast" or "slow," you will never be able to use enough of them to slow down the game's framerate unless you are doing an insanely long series of calculations 30+ times per second. I dunno why people still have the idea that such things matter when it comes to performance.
11-20-2008, 07:29 AM#10
MaD[Lion]
that is true grim. Using it for 1 time thing is fine. But he is talking about circula motion, i asume he wanna periodically move something. And i think he maybe wanna move more than 1 unit, which leads to 30+ per seconds. Therefore avoiding such things is better. And from wat i know Squareroot is faster than Sin or Cos (especially when using sin and cos).
But in the case where u just need to move something in a circle motion around a point, then using the law of circula motion is most efficient.

Quote:
Typically, division and square root take 10
to 20 machine cycles on a processor that does a multiplication in the same precision in 2 or
3 cycles
I believe Sin/Cos cant be faster than division, therefore not squareroot either...
I read this here: http://64.233.183.132/search?q=cache...nk&cd=10&gl=no

Map is a demo of the circula motion. I used my Physic system for it cus i was too lazy to write a "unit mover"... its not tat hard to write one particular for this tho. If you write a script just for circula motion then it will be alot faster than my system too. But i just wanted to show u how to use the formulas to do the trick. What my system does is:
It first give a unit a speed which is tangent to the center unit (tats why i first moved them to positions where i knew which direction give a tangent motion), and then i give the unit tat will circula a centripental acceleration through my Homing method which was meant for homing missiles, but the concept is the same: accelerate toward a point, centripental acceleration just means accelerate toward the center.

for grim: oh if u wanna coment on the system dont :P Its an outdated version, the current version is unstable so i dont dare to use it as demos :(
Attached Files
File type: w3mCircula.w3m (80.5 KB)
11-20-2008, 08:17 PM#11
xombie
Plus its easy as sh1t to play with.
11-20-2008, 08:34 PM#12
Zerzax
Thanks for the help guys, much appreciated.

If I may, I'd like to delve into creating projectiles using units. I understand it's fairly complicated and for this whole year I'll get basically no physics...
I'd like to know if it's possible for me to code my own system. I've checked out Anitar's Vector System and I don't understand it very well, though I do get fundamentally what the system is accomplishing.
For one thing, I do know coordinate projections are essential at a specified angle. However, since it is a projectile and I'd like mine to arc on the z-axis, I know it has to use the cosine ratio of some value, and that's where I'm totally clueless. Do you guys have any generalizations or good places to look? I'll check out the forums, but help is appreciated.
I'm looking at various scripts, you guys don't rly have to respond...
11-22-2008, 12:56 AM#13
Ammorth
Quote:
Originally Posted by Zerzax
Thanks for the help guys, much appreciated.

If I may, I'd like to delve into creating projectiles using units. I understand it's fairly complicated and for this whole year I'll get basically no physics...
I'd like to know if it's possible for me to code my own system. I've checked out Anitar's Vector System and I don't understand it very well, though I do get fundamentally what the system is accomplishing.
For one thing, I do know coordinate projections are essential at a specified angle. However, since it is a projectile and I'd like mine to arc on the z-axis, I know it has to use the cosine ratio of some value, and that's where I'm totally clueless. Do you guys have any generalizations or good places to look? I'll check out the forums, but help is appreciated.
I'm looking at various scripts, you guys don't rly have to respond...

There is a parabolic motion in the script section that you can use to simulate projectiles.
11-22-2008, 01:06 AM#14
Zerzax
Moyack's function? I've seen it, I'll give it a try, even if it's not what you're talking about. What I'm planning to do is create projectiles from points that need to reach an x/y/z coordinate that could be shifting, as in the target unit moves. Does this require something different than a standard parabolic function? Again I'm a little confused especially since I'm lacking in the physics department.
11-22-2008, 08:39 PM#15
Limb_Smasher
Quote:
Does this require something different than a standard parabolic function


The standard projectile motion formula is:
Y = Y0 + V0*t + (1/2)*a*t^2

and its really only for straight paths.


I don't see whats wrong with editing missile art.
Because you're gonna need something quite complex. I mean I can think of vectors as a function of time, but if the unit is running it just gets faster and faster. If they change their height, then parabolic functions would work so well, but then again I don't know how your map plays out. So good luck!