Earth Engine
Earth Engine

Reputation: 10466

How System.Windows.Media.Media3D.Matrix3D work

It seems straight forward to define a function like this

/// <summary>
/// Build 3D transform matrix with image of unit vectors of axes, and the image of the origin
/// </summary>
/// <param name="xUnit">The image of x axis unit vector</param>
/// <param name="yUnit">The image of y axis unit vector</param>
/// <param name="zUnit">The image of z axis unit vector</param>
/// <param name="offset">The image of the origin</param>
/// <returns>The matrix</returns>
public static Matrix3D MatrixFromVectors(Vector3D xUnit, Vector3D yUnit, Vector3D zUnit, Vector3D offset)
{
    var m = new Matrix3D(
        xUnit.X, xUnit.Y, xUnit.Z, 0.0, 
        yUnit.X, yUnit.Y, yUnit.Z, 0.0, 
        zUnit.X, zUnit.Y, zUnit.Z, 0.0, 
        0, 0, 0, 1);
    m.Translate(offset);
    return m;
}

However the test code

...
var m = Geo.MatrixFromVectors(vx,vy,vz,new Vector3D(1,2,3));
var result = m.transform(new Vector3D(1,0,0)) //result: equal to vx
...

shows it does not use the offset at all. How to make it work?

Upvotes: 2

Views: 1685

Answers (1)

herzig
herzig

Reputation: 88

The structures in the Media3D Namespace make a distinction between Vectors and Points. Vector3D is used to specify a position independent value in space (such as an Axis, Surface normal, Acceleration etc.), while Point3D is used to specify position.

Because Vectors are not suppsed to carry position Information Matrix3D.Transform(Vector3D) does not apply the offset. It only transforms the direction of the Vector.

If you pass a Point3D instead of a Vector3D to Matrix3D.Transform(Point3D) it works as expected:

...
var m = Geo.MatrixFromVectors(vx,vy,vz,new Vector3D(1,2,3));
var result = m.transform(new Point3D(0,0,0)) // result is 1,2,3
...

Upvotes: 4

Related Questions