Difference between revisions of "User talk:Aleric Inglewood"

From Second Life Wiki
Jump to navigation Jump to search
Line 93: Line 93:
However, if one limits oneself to only normalized vectors, vectors
However, if one limits oneself to only normalized vectors, vectors
with a length 1, then those represent all the points on the surface
with a length 1, then those represent all the points on the surface
of a sphere with radius 1. A surface is obviously two dimensional,
of a sphere with radius 1.
so it should be possible to uniquely identify any position on
 
the surface of such a sphere with only two numbers. One might think
A surface is obviously two dimensional, so it should be possible to
that selecting just two coordinates of the three of the vector will
uniquely identify any point on the surface of such a sphere with
suffice because the third is fixed by the requirement that the sum
only two floating point numbers.
of the squares of the coordinates is 1, but that would only work
 
on a half sphere. For example, if x and y are known then z can still
One might think that selecting just two coordinates of the three of
be either plus the square root of x squared plus y squares, ''or'' minus
the vector will suffice because the third is fixed by the length requirement,
that value. Instead, one could better choose the spherical coordinate system
but that only works for half spheres; for example, if x and y are known
and express the unit vectors in the angular coordinates φ and θ,
then z can still be either plus the square root of x squared plus y squared,
''or'' minus that value.
 
Instead, a better choice would be the [http://mathworld.wolfram.com/SphericalCoordinates.html spherical coordinate system]
and express the unit vectors with the two the angular coordinates φ and θ,
where φ is the angle of the vector with the positive Z axis, and
where φ is the angle of the vector with the positive Z axis, and
θ the angle of the projection of the vector on to the X,Y plane
θ the angle of the projection of the vector on to the X,Y plane
with the positive X axis.
with the positive X axis. In other words, starting with a unit vector
along the positive Z-axis, one can obtain the required point on
the surface of the sphere by first rotating this vector around the
Y axis (towards the positive X axis) by an angle of φ and then rotating
the result around the Z-axis by an angle of θ.

Revision as of 23:58, 15 March 2014

About Coordinate Systems and Rotations

The four coordinate systems

There are four coordinate systems that are related to LSL programming:

  1. World coordinates
  2. Region coordinates
  3. Object coordinates (root prim coordinates)
  4. Prim coordinates

The World coordinates refer to the map, and allow to include the sim in the coordinates, or refer to void water.

Region coordinates are relative to a given sim. The origin is in the South/West corner at height 0. The North/East corner then is 256, 256 and a Z coordinate for the height up to 4096 meter (on opensim you can go even higher).

Object coordinates are relative to the root prim. Hence, if the object is moved or rotated then the orientation of a child prim, when given in object coordinates, doesn't change. In LSL "local position" and "local rotation" refer to this coordinate system. "local" means relative to the root prim.

Prim Coordinates are relative to a given prim. If this prim is the root prim then the Prim Coordinates are the same as the Object Coordinates. For example, if a child prim is a cube with a size of 1,1,1 and one red surface where the center of that surface is at 1,0,0 then it will still be at 1,0,0 no matter how you move or rotate that child prim (relative to the other linked prims).

Positions

A different position of the origin of a coordinate system is easy to understand: You can think of positions as vectors that start in the origin of the coordinate system that they are given in and end in the point that they refer to. While the length of the vector is independent of the rotation of the coordinate system, the three coordinates are not; but a mental picture of an arrow doesn't have little numbers for three coordinates, so that picture works independent of the rotation too.

Since the rotation of the World Coordinate system and the Region Coordinate system is the same (X, Y and Z axis are parallel of both), and since World Coordinates aren't used in many LSL functions to begin with, we will ignore World Coordinates for now and only refer to Region Coordinates, or say "global" when we mean Region Coordinates.

Rotations

An LSL rotation internally stores a vector that is the axis around which to rotate and the angle of the rotation around that axis. Let V = <u, v, w> be the normalized vector (that is, with length 1) around which we rotate and let a be the angle around which we have to rotate. Then the LSL rotation is a quaternion stored as r = <x, y, z, s> = < V * sin(a/2), cos(a/2) >. Thus, r.x = x * sin(a/2), and r.s = cos(a/2) etc. Note that the quaternion is also normalized. Also note that there is a duality here because inverting V (making it point the opposite way) and inverting the angle gives the same rotation; r and -r have different values but are the same rotation. Also note that if you don't rotate at all (a == 0) then it doesn't matter what axis V you pick, which is apparent because V drops out since sin(0) = 0. The quaternion <0, 0, 0, 1> is the ZERO_ROTATION quaternion.

The point of this technical story is to show that for an LSL rotation to make sense in terms of orientation, you need to be able to express a vector in three coordinates (u, v, w above): the axis around which we rotate is expressed relative to the X-, Y- and Z-axes of the coordinate system. Hence, it is the orientation of the X-, Y- and Z-axes that defines the meaning of a rotation in LSL.

In terms of a mental picture the origin with the (orientation of the) three axis, the red X-axis, the green Y-axis and the blue Z-axis is all the reference we need, combined with a vector for position or a quaternion for rotation.

When you edit an object, the viewer shows either 'World' or 'Local' axes, but really the 'World' axes show the wrong origin, shifted to an averaged center of the object, because if the origin was drawn at (0, 0, 0) you'd most likely not see it. The 'Local' ruler shows the correct coordinate system for the selected prim as its Prim Coordinate System. Selecting the root prim with 'Local' ruler on then shows the Object Coordinate System.

The Dimension Of Rotations

As said before, given some coordinate system, any point in space can be represented with a vector. Obviously space is three dimensional, and thus vectors exists of three real values: one needs three distinct floating point numbers, the x coordinate, the y coordinate and the z coordinate to uniquely identify any position in a given coordinate system, any point in space.

However, if one limits oneself to only normalized vectors, vectors with a length 1, then those represent all the points on the surface of a sphere with radius 1.

A surface is obviously two dimensional, so it should be possible to uniquely identify any point on the surface of such a sphere with only two floating point numbers.

One might think that selecting just two coordinates of the three of the vector will suffice because the third is fixed by the length requirement, but that only works for half spheres; for example, if x and y are known then z can still be either plus the square root of x squared plus y squared, or minus that value.

Instead, a better choice would be the spherical coordinate system and express the unit vectors with the two the angular coordinates φ and θ, where φ is the angle of the vector with the positive Z axis, and θ the angle of the projection of the vector on to the X,Y plane with the positive X axis. In other words, starting with a unit vector along the positive Z-axis, one can obtain the required point on the surface of the sphere by first rotating this vector around the Y axis (towards the positive X axis) by an angle of φ and then rotating the result around the Z-axis by an angle of θ.