Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / In desperate need of math help

Author
Message
Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 7th Mar 2008 23:58 Edited at: 8th Mar 2008 00:08
I'm writing a program that uses vectors to calculate the angle objects are supposed to bounce off surfaces at. When a projectile hits a wall, it needs to bounce off at the same angle in the opposite direction, like a laser pointed at a mirror.

I know the vector for the object and the vector for the surface's normal, now I just need the vector it bounces off at, like this:



I did some googling and found that if I convert these vectors into latitude and longitude on a sphere this problem falls in the category of spherical geometry. (Which I know pretty much nothing about) Then all I would need to do is place the third coordinate (which can be converted back to a vector I can use) such that the coordinate for the normal is the midpoint of the other two.

So I think I need the forumla to get midpoints on a sphere. I tried searching the internet but found nothing, or required math I just could not understand and ended up ignoring it for many months. Anyone experienced with this spherical kind of math that might have some advice?

Attachments

Login to view attachments
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 8th Mar 2008 00:20 Edited at: 8th Mar 2008 00:21
You just want the final velocity?

Think about it. The part of the velocity vector normal to the mirror is reflected, the other part remains the same.

let v be the initial velocity
let n be the surface normal. I assume this normal is normalised (of length 1)

n(v.n) is the part of the velocity normal to the surface. Therefore

v- n(v.n) is the other part (parallel to the surface)

Therefore the final velocity is

v - n(v.n) - n(v.n)

=v-2n(v.n)

SUPER BADASS SPACESHIP X: WEBSITE
FORUM TOPIC
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 8th Mar 2008 01:34
17!

[href]mod2software[/href]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Mar 2008 01:52
And here's an example demonstrating what Tank is talking about:
http://forum.thegamecreators.com/?m=forum_view&t=122695&b=6

Though my example is 2D, all holds the same in 3D; it's just another added component to the vectors.

There's nothing 'spherical' about your problem at all.

B = A - 2(A.N)N

A = your object's direction vector
B = the resulting reflection vector
N = normal of the plane hit

A.N = A dot product N


Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 8th Mar 2008 05:38
Wow, I didn't know dot product could be used to subtract the angles like that. Thanks. I studied your code Phaelax and I think I have a pretty good understand what's going on. I'll have to try to code that in 3D tomorrow.

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 8th Mar 2008 17:56
Ok, I made a test project to see how it works in 3D, then copied it into the main program. Everything reflects at the correct angles now. Thanks guys.



Login to post a reply

Server time is: 2024-11-20 00:35:09
Your offset time is: 2024-11-20 00:35:09