Thursday, 20 March 2008
Simple Collision Response for Plane
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
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)
Tuesday, 26 February 2008
Cartesian Coordinate System
Figure 1: Cartesian coordinate system
A point in the coordinate system is represented by a coordinate pair (x, y). The x and y value represent the distances along each axis.
Those who have experience in gaming most probably has experience in 3-dimension as well. Cartesian coordinate system in 3D world needs another axis – z-axis. Z-axis is along side the line that passes through the screen to our eyes.
Figure 2: 3D coordinate system
To represent a line in 2D Cartesian, a function consist of variables can be introduced. In general, a straight line in x and y coordinate system can be represented by
y = mx + c
where y and x are the values represents the point while m is the gradient of the straight line and c is the y value where the straight line intercept to y-axis.
Example:
Figure 3: y = 3x + 2