Data Realms Fan Forums
http://45.55.195.193/

Calculating Reflections, 2D Physics.
http://45.55.195.193/viewtopic.php?f=7&t=45576
Page 1 of 1

Author:  ryry1237 [ Wed Feb 26, 2014 3:11 am ]
Post subject:  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).

Author:  CaveCricket48 [ Wed Feb 26, 2014 3:27 am ]
Post subject:  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.

Author:  Foa [ Wed Feb 26, 2014 5:08 am ]
Post subject:  Re: Calculating Reflections, 2D Physics.

you kinda need trig to go carzy with this, though

Author:  ryry1237 [ Wed Feb 26, 2014 5:46 am ]
Post subject:  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.

Author:  Homophanim [ Wed Feb 26, 2014 5:59 am ]
Post subject:  Re: Calculating Reflections, 2D Physics.

Do your own homework.

Author:  Foa [ Wed Feb 26, 2014 6:05 am ]
Post subject:  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

Author:  maart3n [ Wed Feb 26, 2014 11:57 am ]
Post subject:  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.

Author:  Duh102 [ Wed Feb 26, 2014 6:11 pm ]
Post subject:  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:

Author:  Foa [ Wed Feb 26, 2014 6:38 pm ]
Post subject:  Re: Calculating Reflections, 2D Physics.

so that's distance, radians vector?

Author:  Duh102 [ Wed Feb 26, 2014 7:49 pm ]
Post subject:  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.

Author:  CrazyMLC [ Wed Feb 26, 2014 9:16 pm ]
Post subject:  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.

Author:  ryry1237 [ Thu Feb 27, 2014 7:47 am ]
Post subject:  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.

Author:  Duh102 [ Thu Feb 27, 2014 8:30 am ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/