View unanswered posts | View active topics It is currently Wed Dec 25, 2024 4:52 pm



Reply to topic  [ 13 posts ] 
 Calculating Reflections, 2D Physics. 
Author Message
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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.

Image
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
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Calculating Reflections, 2D Physics.
Image

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
Profile
Data Realms Elite
Data Realms Elite
User avatar

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


Wed Feb 26, 2014 5:08 am
Profile
User avatar

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

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
Profile

Joined: Thu Jan 20, 2011 12:19 am
Posts: 396
Reply with quote
Post Re: Calculating Reflections, 2D Physics.
Do your own homework.


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

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Location: Canadida
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Dec 23, 2008 8:04 pm
Posts: 1545
Reply with quote
Post 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
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Location: Canadida
Reply with quote
Post Re: Calculating Reflections, 2D Physics.
so that's distance, radians vector?


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

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Sun Dec 25, 2011 7:23 am
Posts: 269
Reply with quote
Post 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
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.080s | 14 Queries | GZIP : Off ]