• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Elliptical Moving

Status
Not open for further replies.
Level 33
Joined
Mar 27, 2008
Messages
8,035
I need to move my unit in elliptical manner, here's a picture which will explain it further how the movement is done.

appl103.gif


Is there any useful formula/method to execute this kind of movement ?

Example:
Initially, my unit is at -3 y-axis.
When I cast a spell targeting at +3 y-axis, my unit will move from -3 y-axis > +2 x-axis > -3 y-axis > -2 x-axis > -3 y-axis.
It seems like it goes into full complete circle, but it's not a circle, it's an ellipse.
 
I wanted to code Phoenix's Dive (From DotA), so this would actually be useful to know.

The function here is:

y = (x-2)(x+2)(3/4)

But, this is only works if you start at point (-2, 0).

We want to start at point (0, -3).

The solution is switch the x and y axes.

You end up with a formula y = (x-3)(x+3)(2/9).

You would apply this formula once to make half the ellipse, and then you would apply it again so the unit could go back :p
 
Well, I didn't even take these yet :D

I just figured it out all by myself now. (I took the roots of that function, then I scaled the thing with 2/9 =o (Because for x = 0, y was supposed to be 9, but it's actually 2 over here)

What you need to do is take points from the start point to the end point and add your Y value multiplied by some factor.

This factor will depend on the max width of the ellipse.
The width on the side is going to be equal to the distance from the starting point to the end point divided by 3.

Let distance be the distance from the starting point to the end point.
Let y be the real number given when doing the formula.

You need to add 6/(number of iterations) to your x every iteration.
This x is going to be used in your formula (x-3)(x+3)(2/9).
And that's going to be y.

The offset from the points you're going to take from the starting to the ending point:

offset = (y/2)*(distance/3)

so:

offset = ((x-3)(x+3)(2/9)/2)*(distance/3)
offset = (x-3)(x+3)(1/9)*(distance/3)
offset = (x*x-9)*(distance/27)
offset = (x * x * distance - 9 * distance) / 27

That should do it.

Just keep moving along the line between the start point and the end point and add ((x * x * distance - 9 * distance) / 27) perpendicular to that path.

unitX = pointOnStraightLineX + (x*x*distance-9*distance)/27 * Cos(angle + bj_PI/2)
unitY = pointOnStraightLineY + (x*x*distance-9*distance)/27 * Sin(angle + bj_PI/2)

And when you reach the end point, instead of adding pi/2, subtract it.
angle is the angle between the starting point and the ending point in radians.

I figured out all of this math by myself ^.^
I haven't even taken this stuff at school yet xD
 
Level 3
Joined
Jan 1, 2012
Messages
50
x = r*cos(theta) + h
y = r*sin(theta) + k

i haven't understand all your post (i'm not good in english :/) but for an elliptical moving, the radius on y axis and x axis must be different.

and if you want an elliptical moving in another angle (45°, 20°) you must make a change of axes. (x = ax + b ? or y = ay + b ? as you want, you check the angle with argument of the transformation, like complexe)
 
Apply a transformation matrix to the result of the circular movement.

I doubt they know what that is or how to use one.

edit
Ok, I'm going to make this very simple.

Recall circle polar coordinates
x = r*cos(theta)
y = r*sin(theta)

This retrieves the x and y components of a hypotenuse of length r on a triangle. Think of the triangle inscribed in a circle rotating from 0 to 360 degrees. By increasing theta, you can create rotations on that ellipse.

If the circle isn't centered, you need to add the center in

x = r*cos(theta) + h
y = r*sin(theta) + k


An ellipse does not have only 1 radius, it has many ; |. However, the major axes can be used instead ^_-.

x = a*cos(t) + h
y = b*sin(t) + k


However, t is not theta! It really wouldn't make sense for it to be theta because even when using the major axes, the radius changes as you move around the ellipse. However, t still has a range of 0 to 2*pi, so if you want to rotate along that ellipse, you can still just go from 0 to 2*pi and have it work perfectly.

The stuff I was talking about before was getting the radius and what not... oh well, here it is, short and simple. Keep in mind that t is also measured from the major axis.

This video will help you with more advanced ellipses ; )
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Calculation is done in 3 parts.

1. A circle.
x1 = r * cos(a1)
y1 = r * sin(a1)

r is radius of the ellipse.
a1 is the angle on the circle the point is.

This gives you a circle.

To get an ellipse you use a non symmetrical scaling matrix.

2. A scaling.
x2 = width * x1
y2 = height * y1

width is how wide you want the ellipse to be.
height is how high you want the ellipse to be.

together these make the orientation of the ellipse. I advise making the parameters such that...
width > height is true
this way the ellipse will point towards the origin of rotation making aiming it easier (no angular offsets).

To get the ellipse pointing at an angle, you use a anti-clock-wise rotation matrix.

3. A rotation.
x3 = x2 * cos(a2) - y2 * sin(a2)
y3 = x2 * sin(a2) + y2 * cos(a2)

a2 is the angle of rotation you want the ellipse to be.

Remember to cache the results of cos(a2) and sin(a2) into a variable as those operations are computationally costly.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Magtheridon96, I have no clue what you were trying to do...

temperature, this is the easiest way to make an elipse. Nestharus never actually told you how to rotate the elipse, only how to make a circle and then scale it into an elipse.

Simple 3 stage procedure.
Circle -[scale]-> Static Elipse -[rotate]-> Rotated Elipse

Vector and matrix mathematics is hardly difficult. It is what drives all Direct3D / OpenGL graphics used by multimedia applications.
 
Magtheridon96, I have no clue what you were trying to do...

temperature, this is the easiest way to make an elipse. Nestharus never actually told you how to rotate the elipse, only how to make a circle and then scale it into an elipse.

Simple 3 stage procedure.
Circle -[scale]-> Static Elipse -[rotate]-> Rotated Elipse

Vector and matrix mathematics is hardly difficult. It is what drives all Direct3D / OpenGL graphics used by multimedia applications.

The video talks about rotating ellipses
 
Status
Not open for further replies.
Top