I have to look into quaternions. But can anyone provide with a code example of how to use them?
For example rotating an object around a vector, and transforming an object from one plane to another. I know there are plugins that can handle quaternions (Falcon and Pufferfish has it) but I need to be able to code it myself (RhinoCommon quaternions).
I tried a bit but the results doesnāt make sense to meā¦ What I did was creating a vector from two box corners (see fig below) and created a transform with zero radians rotation. That resulted in a box rotated 180 degrees (the green box below). And the quat.MatrixForm()
(output to T
) results in a weird flattened surface (red).
I obviously donāt have a clue.
Fig 1. The code generating the above:
private void RunScript(double w, Vector3d v, ref object Q, ref object trx)
{
var vec = cp1 - cp0;
vec.Unitize();
var quat = new Rhino.Geometry.Quaternion(rad, vec.X, vec.Y, vec.Z);
var out_rad = 0.0;
var out_vec = Vector3d.Unset;
quat.GetRotation(out out_rad, out out_vec);
var xform = Rhino.Geometry.Transform.Rotation(out_rad, out_vec, cp0);
geo.Transform(xform);
Geo = geo;
T = quat.MatrixForm();
}
Although totally useless, hereās the script:
Quaternion_test.gh (6.4 KB)
< Embarrassed >
// Rolf