CBA_A3
CBA_A3 copied to clipboard
Function to convert vector dir and up to
In my own project I needed a way to convert vectorDir and vectorUp into rotations that are compatible with the rotation attribute in eden. I could not find a solution so I made my own function.
tint_fnc_test = {
param["_obj"];
_vdir = vectorDir _obj;
_vup = vectorUp _obj;
_vcross = _vdir vectorCrossProduct _vup;
_pitch = (_vup#1) atan2 (_vup#2);
_bank = asin (_vup#0);
_yaw = (_vdir#0) atan2 (_vcross#0);
[[360+_pitch] call CBA_fnc_simplifyAngle, [360-_bank] call CBA_fnc_simplifyAngle, [360+_yaw] call CBA_fnc_simplifyAngle];
};
The output is consistent with
(_obj get3DENAttribute "Rotation")#0
I figured this function could be useful for other people, so I've suggested it here. It is similar to getPitchBank in that it gives an array of degrees of rotation, but the difference is that this function is consistent with the representation 3den uses. I don't know a suitable name for this, so feel free to suggest a fitting one. A complementary function from 3den rotation to vectorDir and vectorUp would be fitting, but I'm not sure how that would look yet.
https://gist.github.com/commy2/d60b11fd38cf53f5c2ec02cda0dc3426
I never included it, because apparently BI made/was about to make their own function.
I don't think you got _bank right.
I was thinking someone must've done this before, but I couldn't find the right place to ask. As for bank/rotY, as stated my implementation is consistent with the rotation attribute. I will compare the output of our respective functions and see what difference there is.
The question of the bank is explained by this page https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Relationships_among_the_inverse_trigonometric_functions
You will see that your function uses asin, but as an encoding by atan2.
As a note on a complement function, there is information here about constructing a rotation matrix from Tait-Bryan angles, which should correspond to the system that 3den uses. https://en.wikipedia.org/wiki/Rotation_matrix#General_rotations
Let:
x = _vup#0 == _xUp
You have:
arcsin x
https://www.wolframalpha.com/input/?i=arcsin+x
I have:
arctan [(-x) / sqrt (1 - x²)]
https://www.wolframalpha.com/input/?i=arctan+%5B%28-x%29+%2F+sqrt+%281+-+x%C2%B2%29%5D They don't look equivalent to me. Did I fuck up somewhere? Thing is, I got this from a NASA paper, and I don't think they would give me a sqrt and atan, when it could be expressed as asin.
You can plot them into wolfram alpha as an equation and see that they're (nearly) equivalent. https://www.wolframalpha.com/input/?i=arcsin+x+%3D+arctan+%5B%28-x%29+%2F+sqrt+%281+-+x%C2%B2%29%5D If you look at the graph, they have different polarities, but otherwise, they are the same.
If you remove a minus, like it's written on wikipedia, they are exactly equivalent. https://www.wolframalpha.com/input/?i=arcsin+x+%3D+arctan+%5B%28x%29+%2F+sqrt+%281+-+x%C2%B2%29%5D
As for why NASA decided to do it that way? Well, Wikipedia says: "Useful identities if one only has a fragment of a sine table: " So maybe for their particular application they only have a fragment of a sine table (Whatever that means).
Here's the proof of concept for a complementary function from 3DEN rotation angles to vector dir and up.
fnc_convert3DENRotationToVectorDirAndUp = {
params["_rotation"];
_rotation params ["_rotX", "_rotY", "_rotZ"];
_vectorDirAndUp = [
[
(cos _rotY) * (sin _rotZ),
(cos _rotX)*(cos _rotZ)+(sin _rotX)*(sin _rotY)*(sin _rotZ),
-(sin _rotX)*(cos _rotZ)+(cos _rotX)*(sin _rotY)*(sin _rotZ)
],
[
-sin _rotY,
(sin _rotX)*(cos _rotY),
(cos _rotX)*(cos _rotY)
]
];
_vectorDirAndUp
};
Do we have the reverse?
Which do you mean? The first function was vectorDirAndUp -> 3DEN rotation and the one I posted just now is 3DEN rotation -> vectorDirAndUp. So the answer is yes unless you're thinking of something else?
Ah, I see. Missed the "complementary". That solves it then.