SDK Question Surface curvature to Vessel relative co-ordinates

dumbo2007

Crazy about real time sims
Joined
Nov 29, 2009
Messages
675
Reaction score
0
Points
0
Location
India
Hi,

I need some help regarding transformations again :)

I am trying to make a Rover addon which is integrated with Bullet Physics. The rover is a vessel which is attached to another vessel(which serves as a controlling base). The rover moves on a plane in the Physics world. I copy this position into Orbiter by moving the attachment point connecting the rover vessel and base vessel, to the position that the physics gives me. However on the Moon's surface, the rover's wheels leave the surface at longer distances due to the Moon's curvature. The difference becomes noticeable over a distance of about a km or so.

I understand that I have to somehow force the rover downwards as it moves further out as the moon's surface is not a plane. I am searching for an easy way to convert the vessel relative co-ordinates to the moon's surface co-ordinates.

So if we assume that the rover moves along the z axis of the base vessel, then at some point it will leave the moon's surface say z=1000. This is because the rover is moving in the base vessel's relative co-ordinates while I want the vessel to move along the curving surface. So given a distance of 10 along the surface, I need to convert this to the corresponding co-ordinates wrt the the base vessel.

I hope I was able to explain clearly.

Thanks!
 
You need to alter the value of y by:

[math]\left(1-\cos\left(\frac{\sqrt{x^2 + z^2}}{R}\right)\right) R[/math]

But I think you will need additionally rotate your vessel too.
 
Thanks Orb!

Yes...is there an easy way to calculate the rotation around the 3 axes ? So basically I need the same orientation as the tangent immediately below the point on the surface of the sphere.

Its easy in 2D.....but 3D phew! :facepalm:

I was planning to insert physics inside vessels and luckily they don't curve!

Orulex manages to follow the curve somehow I think by making the heightmap run along the surface.
 
Yes...is there an easy way to calculate the rotation around the 3 axes ? So basically I need the same orientation as the tangent immediately below the point on the surface of the sphere.
The rotation axis is the cross product of:
  • A vector from the centre of the Moon to your vessel; with
  • A vector from the centre of the Moon to your base origin.
(normalized and converted to the local vessel frame, of course)

The rotation angle is the arccosine of the dot product of those two vectors.
 
I've been thinking about this problem further. orb's solution will work when the distance from the base is relatively small but the further you go from the base, you will want to adjust the x and z components also because you are not traveling along a flat plane. For an extreme example, consider that you are one planet radius away from the base. Applying orb's adjustment will place you an angular distance of pi/2 radians away from the base instead of the one radian that you should be.

On the issue of rotating the vessel, I think the best solution would be to calculate the rotation matrix for the vessel directly. In the base vessel frame, the rotation matrix for the surface reference frame should be constructed from three column vectors. The second column will be the normalized radius vector for the vessel. The first and third vectors will be either unit vectors parallel to the base vessel x and z axes or, if you want greater accuracy, you will also need to adjust these for the curvature of the planet. You can the multiply rotation matrix for the vessel that you get from your physics engine by the rotation matrix for the surface reference frame to get the rotation matrix for the vessel in the base vessel reference frame. You can multiply this matrix by the rotation matrix of the base vessel to get the rotation matrix of the vessel in the global frame.

I know that doesn't give you all the answers in "recipe format" but hopefully it is enough to help.
 
Last edited:
There is 1 thing though. I already have a rotation for the vessel wrt the surface. This rotation is for orienting the vessel wrt the base or if there is some terrain underneath the vessel which causes it to orient itself in a particular way. So the "planetary curvature rotation matrix" that I calculate, has to be added to this matrix.

But I think 2 rotations can be applied successively by simply multiplying the rotation matrices.
 
But I think 2 rotations can be applied successively by simply multiplying the rotation matrices.
That is correct. The order of multiplication is important though because matrix multiplications are not commutative. In this case, you want to multiply the rotation wrt the surface by the rotation of the surface wrt to the base. In this regard, I realise I made an error in my previous post, which I'll edit shortly to correct it.
 
The better solution to get a nice movement along the surface of the sphere would be to only use rotations, as such a movement is just a rotation about an axis passing through the center of the sphere.

Let's say the center of the sphere (the Moon, in this case) is at (0,0,0) (if it's not, you will need to change coordinates a bit for this method to work). Let the position of the rover be described by vector [math]\vec{x}[/math], and the direction of movement by [math]\vec{f}[/math].

The rotation axis will be [math]\vec{x} \times \vec{f}[/math] (you might want to normalize it, too) and the angle will be [math]\frac{d}{R}[/math], where d is the distance the rover is supposed to travel, and R is the radius of the sphere (Moon).

Then you just need to apply the rotation to vectors [math]\vec{x}[/math] and [math]\vec{f}[/math] to get the new position and movement direction.

If you want to turn, which will be just changing the [math]\vec{f}[/math] vector, you need to rotate it about the axis [math]\vec{x}[/math] (again, you might want to normalize it) by the desired turn angle.
 
You can split the rotation into three component rotations around the principal axes. Let's say you start out with your rover located at x=(R,0,0), i.e. longitude=0, latitude=0, and facing north.

The first rotation is around the x-axis, given heading h:
[math]
R_1 = \left[\begin{array}{ccc}
1 & 0 & 0 \\ 0 & \cos h & -\sin h \\ 0 & \sin h & \cos h
\end{array}\right]
[/math]
The second rotation is around z for latitude a:
[math]
R_2 = \left[\begin{array}{ccc}
\cos a & -\sin a & 0 \\ \sin a & \cos a & 0 \\ 0 & 0 & 1
\end{array}\right]
[/math]
And finally a rotation around y for longitude d:
[math]
R_3 = \left[\begin{array}{ccc}
\cos d & 0 & -\sin d \\ 0 & 1 & 0 \\ \sin d & 0 & \cos d
\end{array}\right]
[/math]
which gives you your final rotation
[math]
R = R_3 R_2 R_1
[/math]
so that
[math]
x' = Rx
[/math]
(note that you may have to transpose some of the matrices, i.e. swap the signs of the sines - I didn't check that.)
 
Orulex manages to follow the curve somehow I think by making the heightmap run along the surface.

Orulex computes to spherical coordinates from the Mercator-heightmap, as far as I know. It never assumes non-spherical terrain in the first place.
 
Back
Top