Skip to main content
gamedev.net
🔒 Locked

Convert formula

Started by ProblemBaby Nov 16, 2004 at 4:18 PM 4 replies 950+ views
Original Post
ProblemBaby
ProblemBaby
Hi Ive some code that looks like this it is collision code for balls: // x, y = length between centers // xv0, xv0, yv1, yv1 = velocity vectors for ball0 and ball1 length = BIOS_Sqrt(x*x+y*y); normal_x = x / length; normal_y = y / length; a = DotProduct(normal_x, normal_y, xDiff, yDiff); xn = normal_x * a; yn = normal_y * a; xv0 += xn; yv0 += yn; xv1 -= xn; yv1 -= yn; Its works amazing but I want to do it with polar coordinates angle and length intead of x, y for the speed. Is it possible to do?? or do Ive to convert first to x,y and then back to angle,length? If it is possible please give me a hint on how to do it Thanks in advance
Problems every where
JohnBolton
JohnBolton
I don't think there is a faster or easier way to do it than to convert to x/y, add them, and then convert back.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
LilBudyWizer
LilBudyWizer
The dot product for two polar vectors (r1,t1) and (r2,t2) is |r1||r2|cos(t1-t2).
Keys to success: Ability, ambition and opportunity.
ProblemBaby
ProblemBaby
xn = normal_x * a;
yn = normal_y * a;

xv0 += xn;
yv0 += yn;
xv1 -= xn;
yv1 -= yn;


isnt this possible to do much simplier with polar coordinates??

I know it cant be
vel0 += a;
vel1 -= a;

But I cant either find out how to do it!
Isnt it possible

LilBudWizer: Thanks, that took me one step closer
Problems every where
ProblemBaby
ProblemBaby
Then I also wonder if it is possible to find out the length of a side in a triangle if I know the two other lengths and the angle between them.
I know I can use sqrt and dont need the angle

but isnt it somehow possible to do it witout sqrt and use the angle instead in some way?
Problems every where
SuperNerd
SuperNerd
Try using Sin and Cos to change the position of the ball or whatever is moving
x += Sin(angle)*length;
y += Cos(angle)*length;

if you need to find the angle it's pretty easy with Atan2

angle = Atan2(point1y-point2y,point1x-point2x);

I tried to make the variables self explanitory;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.