# Homogenous coordinates for physics engine

This topic is 3972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on a 2D physics engine, which finally got me to understand the need for homogenous coordinates. Since you can represent a position and orientation in space using a matrix and homogenous coordinates, suppose you represented the position and orientation of a body in a physics engine as a matrix. Leaving numerical issues aside for the moment, when would this be a good idea? Would it ever be a good idea? And how would you represent something like integration, like position = velocity * time + 1/2 accel * time^2?

##### Share on other sites
[edit:] Pay no attention to the following.

If you mean as a single matrix, then never. The position of a body and the orientation in 2-space of a body should in most cases each be represented as a 2-element vector. Trying to combine these two vectors conflates two notions which are completely independent.

[Edited by - liquiddark on December 5, 2007 10:57:37 PM]

##### Share on other sites
Quote:
 Original post by liquiddark Trying to combine these two vectors conflates two notions which are completely independent.

Not at all. Position and orientation in 2-space can be represented as a 3x3 matrix, for the same reason that position and orientation in 3-space can be represented as a 4x4 matrix. Doing this for a physics engine may or may not be the best idea, but it's certainly not a horrible idea.

Angular velocity does not take well to a matrix representation. I would suggest storing it directly as a scalar radians per second.

##### Share on other sites
Quote:
 Original post by SneftelNot at all. Position and orientation in 2-space can be represented as a 3x3 matrix, for the same reason that position and orientation in 3-space can be represented as a 4x4 matrix. Doing this for a physics engine may or may not be the best idea, but it's certainly not a horrible idea.

 Pay no attention to the following.

Fair enough. I'd be interested to see the usage which demands this representation for 2 dimensions, however.

[Edited by - liquiddark on December 5, 2007 10:41:24 PM]

##### Share on other sites
Nothing demands it, but it's more efficient for rotating objects than bare trig, for the same reason that it's more efficient to do it with matrices in 3D: the change of basis is expressed as an easy-to-calculate linear equation.

##### Share on other sites
I came to the point where I needed some way to represent an affine transformation (more specifically, a rotation and translation) for a long tree of parent-daughter relationships. Articulated bodies using lots of joints is the obvious use, but I was also imagining things like bodies existing inside other bodies. I could either create an affine transformation class, or I could make my vectors homogeneous and use matricies as my affine transformation. An unintended benefit I derived, if I understand things right, is the ability to easily represent infinity, so I think this is the right direction to go.

As for representing bodies as matricies, a possible use I'm imagining in my naiveness is a swept SAT test using matricies instead of vector positions. I've implemented a swept SAT test that assumes no rotation. Wasn't all that difficult to do, but my understanding is that it's significantly more difficult to handle swept SAT with rotating bodies. Representing the position and orientation of a body as a single matrix made me wonder if you could substitute these matricies in to the swept SAT and arrive at a method that also handles rotations during a frame.

I don't know if it's possible to "project" a matrix on to a separating axis. Or maybe you could project the separating axis on to a matrix? It just seems to me that there might be times where storing a point's position and orientation would be useful, and I'm curious if anyone has any experience playing in this area.

Also, I'm curious how calculus (the sort of simple calculus involved in physics engines) would work with a matrix representation.

##### Share on other sites
I found this page and this page talking about angular velocity and matricies. I'm starting to think the problem with this representation is that it doesn't easily allow integration of angular velocity.

In most integration schemes, you have angle += angular velocity * time. (The integration assumes constant angular velocity). However, storing the angle in matrix form, you lose information (specifically, the angle). The real final rotation matrix you want is:

[[ cos(theta + omega * time), -sin(theta + omega * time), 0] [ sin(theta + omega * time),  cos(theta + omega * time), 0] [                         0,                          0, 1]]

But I don't think there's a way to arrive at this matrix from the rotation matrix:

[[ cos(theta), -sin(theta), 0] [ sin(theta),  cos(theta), 0] [          0,           0, 1]]

I've tried using trig identities and subtracting the first from the second, but I haven't managed to arrive at something that would work.

[Edited by - Numsgil on December 6, 2007 12:30:13 PM]

##### Share on other sites
I have been worrying about angular velocities (in 3d) myself in the recent past. I'll try to share my interpretation(corrections are welcome) and learn a few things from your thread :)

Some important points about angular velocity.

1. An object not rotating about its center of mass but moving in a straight line still has non zero angular velocity. The angular velocity would be zero only if measured about the CM.

2. An object rotating in free space (no external forces) will maintain its rotational kinetic energy. This does not imply that its angular velocity (as measured w.r.t. some external fixed coordinate system (world space)) is constant. The axis of rotation (and hence the angular velocity) could still be changing dynamically.

The angular velocity to skew symmetric approach to compute the change in orientation matrix (which then updates the orientation matrix by adding to it) is an approximation. It assumes that the angular displacement (change in theta) is very small. So that,

Cos (dTheta) is almost one
Sin (dTheta) is almost equal to dTheta

If you substitute these into your matrices above, they will match.

##### Share on other sites
Quote:
 Original post by NumsgilI found this page and this page talking about angular velocity and matricies. I'm starting to think the problem with this representation is that it doesn't easily allow integration of angular velocity.In most integration schemes, you have angle += angular velocity * time. (The integration assumes constant angular velocity). However, storing the angle in matrix form, you lose information (specifically, the angle). The real final rotation matrix you want is:[[ cos(theta + omega * time), -sin(theta + omega * time), 0] [ sin(theta + omega * time), cos(theta + omega * time), 0] [ 0, 0, 1]]But I don't think there's a way to arrive at this matrix from the rotation matrix:[[ cos(theta), -sin(theta), 0] [ sin(theta), cos(theta), 0] [ 0, 0, 1]]I've tried using trig identities and subtracting the first from the second, but I haven't managed to arrive at something that would work.

Sure there is. Given R(theta) to be the rotation matrix generated for an angle theta, R(theta1+theta2) is just R(theta1)*R(theta2). It works just like combining transformation matrices always works.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632996
• Total Posts
3009776
• ### Who's Online (See full list)

There are no registered users currently online

×