# angle & direction after collision

• (2 Pages)
• 1
• 2

## 24 Replies - 11769 Views - Last Post: 21 December 2009 - 04:09 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=145214&amp;s=efd70c70b37958d2d60c635c740cbfa9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

# angle & direction after collision

Posted 13 December 2009 - 07:03 AM

Hi,

Im working on detecting collision of ball in parabolic motion with some other ball, recangle etc, what i have is

Quote

position of ball
speed
current angle
detected collision
collision position

and what i need is

Quote

angle
direction

after collision and , it need to work on all objects no matter what shape there are which is hard i think.

i tried doing this myself but i failed, so i dont have any woking or half-working code.

Is This A Good Question/Topic? 0

## Replies To: angle & direction after collision

### #2 bsaunders

Reputation: 44
• Posts: 571
• Joined: 18-January 09

## Re: angle & direction after collision

Posted 13 December 2009 - 10:35 AM

Is it 2-D collision like this?

### #3 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

## Re: angle & direction after collision

Posted 13 December 2009 - 12:51 PM

well ball is much smaller than rectangle and usually jump into it becouse of speed but i think it doesnt matter so much, and yes collision looks sth like that you showed but ofc it can happen on whole recangle.

### #4 stayscrisp

• フカユ

Reputation: 1040
• Posts: 4,325
• Joined: 14-February 08

## Re: angle & direction after collision

Posted 13 December 2009 - 03:11 PM

check out this link http://www.peroxide....n/collision.pdf its hard going though!

### #5 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

## Re: angle & direction after collision

Posted 13 December 2009 - 04:09 PM

Thanks for link, interesting, but it covers only "sliding collision" and "preventing object from going thru some other object it should collide" right ?
If so i need only angle and direction after collision sth like this http://en.wikipedia....astic_collision
ofc i tried those formulas from wiki but it wasnt working.

### #6 bsaunders

Reputation: 44
• Posts: 571
• Joined: 18-January 09

## Re: angle & direction after collision

Posted 14 December 2009 - 10:17 AM

Okay, so is this what you mean by angle of collision?

Also, what are the other possible shapes of objects? And what do you mean my direction of collision?

This post has been edited by bsaunders: 14 December 2009 - 10:18 AM

### #7 bsaunders

Reputation: 44
• Posts: 571
• Joined: 18-January 09

## Re: angle & direction after collision

Posted 14 December 2009 - 10:29 AM

By direction, do you mean the direction the object was moving in before it collided?

### #8 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

## Re: angle & direction after collision

Posted 14 December 2009 - 11:51 AM

here is example of what i mean by direction:

if ball hits rectangle on UP or DOWN side only "vector.y" will change if LEFT or RIGHT the "vector.x" will change, but i think it will come from calculated angle.

and i found great site about what im trying to accomplish : http://graja.net/eks...Przeszkody.html its in poliss but it doesnt matter.

Quote

Also, what are the other possible shapes of objects

well all possible, look at that link i posted

### #9 bsaunders

Reputation: 44
• Posts: 571
• Joined: 18-January 09

## Re: angle & direction after collision

Posted 14 December 2009 - 12:16 PM

I'm having a hard time visualizing this. So you have an ellipse moving parabolically, and there are other objects in the path of that ellipse, and you want to find the angle and direction of the collision of the ellipse and the object, right? The animation on the link you provide had a ball moving on a straight path.

This post has been edited by bsaunders: 14 December 2009 - 12:17 PM

### #10 stayscrisp

• フカユ

Reputation: 1040
• Posts: 4,325
• Joined: 14-February 08

## Re: angle & direction after collision

Posted 14 December 2009 - 12:33 PM

@bsaunders

Basically what he is saying is that he wants the calculations to work out how an object will bouce from a certain angle, lets say you throw a ball at a wall.

If your throw it straight it will return on essentially the same angle, whereas if you throw it from the left it will bounce off at an angle.

So how to get directional vector B from directional vector A, after the collision with the plane.

I think

@devcom
Can you give some code that you have tried?

### #11 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

## Re: angle & direction after collision

Posted 14 December 2009 - 01:03 PM

ok, lets say i have nothing, and i want to create sth like that ball in that last link, what do you suggest ( i mean besides to know trig etc.)
if i will have sth like that ball i can do the rest

### #12 bsaunders

Reputation: 44
• Posts: 571
• Joined: 18-January 09

## Re: angle & direction after collision

Posted 14 December 2009 - 01:33 PM

You can start by creating a Ball class.

### #13 devcom

Reputation: 0
• Posts: 15
• Joined: 11-November 09

## Re: angle & direction after collision

Posted 14 December 2009 - 02:04 PM

well i have it, i just need the calculations, no whole code

### #14 stayscrisp

• フカユ

Reputation: 1040
• Posts: 4,325
• Joined: 14-February 08

## Re: angle & direction after collision

Posted 14 December 2009 - 05:39 PM

Well, take the dot product of the first directional vector and the normal of the plane the object collided into

V = velocity vector

N = normal of plane

. = dot product

R = new vector

(V . N)*N

This projects V onto N, now to get a reflecting vector

R = 2*(V . N)*N - V

and getting a bounce vector

R = -2*(V . N)*N +V

### #15 PixelStation

Reputation: 4
• Posts: 44
• Joined: 12-November 09

## Re: angle & direction after collision

Posted 14 December 2009 - 08:40 PM

I love this book for all the motion and physics examples. Sometimes it can get a little hard to follow, but looking on google usually helps that.

Here's the link: clicky, then go to "Chapter 13: Playing God: Basic Physics Modeling", then to "5 Basic Ad Hoc Collision Response"