Showing posts with label Dot Product. Show all posts
Showing posts with label Dot Product. Show all posts

Thursday, 20 March 2008

Simple Collision Response for Plane

Lets say we have a plane (B) with a slope of (delta Y / delta X), the slope of the normal (n) must be (-delta X / delta Y). In vector form, thats the same as B = [delta X, delta Y] and n = [delta Y, -delta X].

Let's assume the incoming velocity as U, the result velocity as R.
Now, it's time to find the projection (P) of -U onto the normalized normal (N).
By using dot product of -U and N, we will get the length of the projection on N.
Thus, P = (-U . N) * N --> Eq. 1

To find the reflection, we add in V where V = U + P --> Eq. 2.
Result velocity (R) = P + V --> Eq.3

Substitute Eq.2 into Eq.3,
R = P + U + P
= 2 * P + U

Substitute Eq.1 into it,
R = U + 2 * (-U . N)N or R = U - 2 * (U . N)N

Dot product and Cross Product

Dot Product
A.B = |A||B|cos(angle)

A.B = a1b1 + a2b2 + a3b3
where A = [a1 a2 a3], B = [b1 b2 b3]

If A.B = 0, then |A|B|cos(angle) = 0,
acos(0) = 90degree.
Thus, A is perpendicular to B,

If A.B <> 90 degree
If A.B > 0, angle <>

** Dot product provides the length of the projection of one vector to another.
If A is going to project on to B, B must be normalised.

Cross Product
A x B = [(a2b3 - a3b2) (a3b1 - a1b3) (a1b2 - a2b1)]
where A = [a1 a2 a3], B = [b1 b2 b3]

A x B is perpendicular to both A and B.
A x B = -(B x A)

|A x B| = |A||B| sin(angle)