Some easy equation :roll:

Discussion about everything. New games, 3d math, development tips...
Post Reply
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Some easy equation :roll:

Post by Vsk »

Hi, I have resolved this equation earlier (year ago) but don't remember what was the "trick". Is something with some trigonometric equivalent.

I need to know how obtain the angle of which a proyectil should shoot itsefl to give a blank into x, y coords.

This is, I have a point where the shoot begins with some angle alpha (imagine everyting 2d) and some other point in different x and Y.

This just the easy "free fall" equations but I can not obtain alpha :oops:.

I am using this two:

xf = xi + |vox|*t
and
yf = yi + |voy|*t + (g*t^2)/2.

vox = original velocity in X
vox = origina velocity in Y

I replace the time in the second using the one (try it and see for your self).


I finish with some trigonometric iguality where I can not get alpha (easily):oops:

what I need is alpha = asin or acos or atan of f(yf,yi,xf,xi,g). just that.

Any good of you are good in maths?

Thanks
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

If your initial shooting speeds are correctly calculated(i havent checked) then by drawing a triangle

tan alpha = opposite side/adjacent side

Code: Select all

  /| 
 / |oppsoite (vertical velocity)
/__|
adjacent (horizontal velocity)
angle is then = atan (Vertical/horizontal).

when you code it rember trig functions in c and c++ operate in radians not degrees.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

omaremad wrote:If your initial shooting speeds are correctly calculated(i havent checked) then by drawing a triangle

tan alpha = opposite side/adjacent side

Code: Select all

  /| 
 / |oppsoite (vertical velocity)
/__|
adjacent (horizontal velocity)
angle is then = atan (Vertical/horizontal).

when you code it rember trig functions in c and c++ operate in radians not degrees.
Thanks but that is not my prolem.
My problem is just a theorical calclation, outside the program.
With the two equation that I have posted is enoght to obtain the alpha angle to shoot to a x,y point from xo,yo.
The only thing that I want is to resolve this sistem of equation, and although I am good at resolving, at the end of the equation I obtain some sin and cos equation where I can obtain alpha but I need to do some trigonometric tric that I have not figered out.
Give it a try, and yo will see.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

i dont really understand what you mean, but you want to make one function that gives the result?
alpha = asin or acos or atan of f(yf,yi,xf,xi,g)
You already have it... i dont get what you mean.

The sin / cos equations i think you are talking about resolve the velocity into its vertical and horizontal components, since you already have these 2 velcoities im guessing you want the final velocity(the opposite)?


you can do that via pythagoras(and my ascii triangle) or add verticalVel*sin(alpha)+horizontalVel*cos(alpha)
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Vsk
Posts: 343
Joined: Thu Sep 27, 2007 4:43 pm

Post by Vsk »

omaremad wrote:i dont really understand what you mean, but you want to make one function that gives the result?
alpha = asin or acos or atan of f(yf,yi,xf,xi,g)
You already have it... i dont get what you mean.

The sin / cos equations i think you are talking about resolve the velocity into its vertical and horizontal components, since you already have these 2 velcoities im guessing you want the final velocity(the opposite)?


you can do that via pythagoras(and my ascii triangle) or add verticalVel*sin(alpha)+horizontalVel*cos(alpha)
What I have:
-intial velocity (not in x or y) just the initail one (only the scalar value).
-gravity
-y initial, x initial y final, x final.

Using this equations:

xf = xi + |vox|*t
and
yf = yi + |voy|*t + (g*t^2)/2.

the only parameter that I don't have and want is the alpha value with which I botain |vox| and |voy|.

I make it more clear: (I know I should do it earlier).

xf = xi + |vox|*t
xf = xi + |vo|*cos(alpha)*t;

yf = yi + |voy|*t + (g*t^2)/2
yf = yi + |vo|*sin(alpha)*t + ((g*t^2)/2

so:
Replacing time from first equation we have:

yf = yi + |vo|* sin(alpha)*((Xf-xi)/(|vo|*cos(alpah)) + (g*((Xf-xi)/(|vo|*cos(alpah))^2 )/2

In this las one equation we have that the only incongit is alpha cause I have the rest of paramters, so the only thing to do is conitnue resolving it.

Here is my problem, cause you must apply some trigonometric equivlente to finaly have either atan, acos or asin, whatever , it doen matter.

Take this last one and try to resolve it. You will find with what I mean.

[EDIT] and you are right I miss some parameter:

alpha = asin or acos or atan of f(yf,yi,xf,xi,g,|vo|)
Post Reply