Direction of normal

Member
Posts: 131
Joined: 2010.08
Post: #1
I want to make a circle bounce from surfaces when a key is pressed in the way that the ball in N-Ball does, so that its velocity in the direction of the surface's normal becomes a value that has a constant magnitude and its velocity in the direction that is parallel to the surface does not change. This is not a physics engine question, only a mathematical one. How to do it? I am asking this as I can not yet do vector maths well (I know only its basics).
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Simple, you just need to subtract out the normal component from the velocity.

Velocity component parallel to the normal:
vNormal = dot(velocity, n)*n

Velocity component perpendicular to the normal:
vTangent = velocity - vNormal

Your desired normal velocity:
vDesired = n*desired

Putting it all together:
vResult = vTangent + vDesired

Which simplifies to:
vResult = velocity + (desired - dot(velocity, n))*n

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 131
Joined: 2010.08
Post: #3
Thanks. Do I need to find the collision surface's normal myself, as Chipmunk does not seem to have a query for it?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
You can get collision normals from the cpArbiter struct passed to your collision handler callback. (See http://files.slembcke.net/chipmunk/relea...cpArbiter)

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Smooth acceleration in every direction. Honey Sharma 1 4,865 Aug 16, 2011 01:37 AM
Last Post: PoseMotion
  newbie request direction Teehee 3 6,471 Jul 27, 2011 09:57 AM
Last Post: AndyKorth
  give direction to sprite termitis 9 10,812 Mar 11, 2011 02:38 PM
Last Post: compiler
  Direction formula? TimMcD 2 5,947 Nov 11, 2009 11:42 PM
Last Post: TimMcD
  Triangle Normal Calculations merrill541 2 3,545 Feb 1, 2009 07:06 PM
Last Post: merrill541