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

Eigla

Joined: Tue Jun 12, 2007 11:52 pm Posts: 12807 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.

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.

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

maart3n

Joined: Tue Dec 23, 2008 8:04 pm Posts: 1531

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

Duh102

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:

You want the vector that is reflected over the normal of the surface, so you have to first figure out the normal of the surface: If we define dx=x2-x1 and dy=y2-y1, then the normals are (-dy, dx) and (dy, -dx). (src) Once you have the norm of the line, you can then compute the reflection. Vect1 is the direction of the ball before hitting the wall Vect2 is after the wall WallN is the normal of the wall DOT is the dot product Vect2 = Vect1 - 2 * WallN * (WallN DOT Vect1) (src) If you don't know how to take the dot product: Given two vectors (A,B) and (C,D), the dot product is AC + BD

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

CrazyMLC

Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 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

ryry1237

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.

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

Duh102

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.

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