View unanswered posts | View active topics It is currently Sun Jan 26, 2020 1:25 pm

 Page 1 of 1 [ 13 posts ]
 Print view Previous topic | Next topic
Calculating Reflections, 2D Physics.
Author Message

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Calculating Reflections, 2D Physics.
Good day Datarealm forums,

I'm trying to figure out a seemingly simple problem here, but somehow I'm getting mentally stuck.

Given an x-velocity and y-velocity of an object, and the angular orientation of the object that we are reflecting stuff off of, what will be the resulting x-velocity and y-velocity of the object? (assume zero loss in speed).

Wed Feb 26, 2014 3:11 am

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 12200
Location: Here
Re: Calculating Reflections, 2D Physics.

Angle A is the same as angle B.

All you need to do is find the angle between the first red line (A) with the black line, and then rotate the red line.

Wed Feb 26, 2014 3:27 am
Data Realms Elite

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Re: Calculating Reflections, 2D Physics.
you kinda need trig to go carzy with this, though

Wed Feb 26, 2014 5:08 am

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Re: Calculating Reflections, 2D Physics.
CaveCricket48 wrote:

Angle A is the same as angle B.

All you need to do is find the angle between the first red line (A) with the black line, and then rotate the red line.

I know about the angle a equals angle b part.
I'm just looking to see if there's some formally defined formula where I can plug in the different values and get the correct x/y result.
It's easy for me to find the values for any individual case, I'm just looking for a general formula for all cases.

Wed Feb 26, 2014 5:46 am

Joined: Thu Jan 20, 2011 12:19 am
Posts: 395
Re: Calculating Reflections, 2D Physics.

Wed Feb 26, 2014 5:59 am
Data Realms Elite

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Re: Calculating Reflections, 2D Physics.
ryry1237 wrote:
CaveCricket48 wrote:
[]http://i1.minus.com/iGe1fNRWpyTu7.png[/]

Angle A is the same as angle B.

All you need to do is find the angle between the first red line (A) with the black line, and then rotate the red line.

I know about the angle a equals angle b part.
I'm just looking to see if there's some formally defined formula where I can plug in the different values and get the correct x/y result.
It's easy for me to find the values for any individual case, I'm just looking for a general formula for all cases.

trig, yo

Wed Feb 26, 2014 6:05 am

Joined: Tue Dec 23, 2008 8:04 pm
Posts: 1530
Re: Calculating Reflections, 2D Physics.
Let's say your input vector is: x=1 y=1
Then your output will be: x=1 y=-1

The horizontal direction(in the image cricket posted) stays the same. The vertical direction reverses.

Wed Feb 26, 2014 11:57 am
happy carebear mom

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7094
Location: b8bbd5
Re: Calculating Reflections, 2D Physics.
He needs it for an arbitrary surface angle, it seems.
If you don't feel like doing a half second Google search, here's a formula that will work:

Wed Feb 26, 2014 6:11 pm
Data Realms Elite

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Re: Calculating Reflections, 2D Physics.

Wed Feb 26, 2014 6:38 pm
happy carebear mom

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7094
Location: b8bbd5
Re: Calculating Reflections, 2D Physics.
The line can be defined in any way as long as you can get the dx and dy values. The motion vector is just what you'd expect, the components of the motion of whatever it is. They both have to be on the same cartesian plane of course, +x and -x, +y and -y going the same directions.

Wed Feb 26, 2014 7:49 pm

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4771
Location: Good news everyone!
Re: Calculating Reflections, 2D Physics.
If Duh's explanation doesn't clear things up (something I didn't know) there's also arctangent2, which lets you find the angle of a vector. You could use that to do your calculations.

After you find the new angle, you can take the sin of the angle and multiply it by the vector magnitude for the y speed, and multiply the cos of the angle by the vector magnitude to get the x speed. (The magnitude may have been reduced because of the bounce, depends on how efficient the collision was)

If none of that makes sense to you, you should learn a bit of trigonometry.

Wed Feb 26, 2014 9:16 pm

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Re: Calculating Reflections, 2D Physics.
I quite like Duh's explanation.
I was originally using atan to find the angle of the incoming object, and then using cos and sin to calculate the resultant vectors...

Code:
// Given object dx, object dy, and reflection angle THETA
// 1. determine angle of incoming object
float angle;
if (dx > 0)
angle = atan(dy/dx);
else if(dx < 0)
angle =-atan(dy/dx);
// I also have cases for dealing with dy = 0, but to save writing I'll omit that.

// 2. determine resultant dx and dy values
float velocity = sqrt(dx^2 + dy^2)
dx2 = cos(2*THETA - Angle + pi) * velocity
dy2 = sin(2*THETA - Angle + pi) * velocity

But Duh's approach of using the dot product seems to be more computationally efficient, not to mention being easier on the eyes than a bunch of trig being thrown around.

Also, this is not homework. This is merely idle curiosity where I have an answer, but I'm looking if there is a better one.

Cheers Duh.

Thu Feb 27, 2014 7:47 am
happy carebear mom

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7094
Location: b8bbd5
Re: Calculating Reflections, 2D Physics.
Using matrices instead of trig has the added benefit of being similar for n-dimensional computations. The same method of finding the norm and doing stuff with the dot product works for 3d vectors as well.

Thu Feb 27, 2014 8:30 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 13 posts ]

#### Who is online

Users browsing this forum: Google [Bot]

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback