Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to convert vector dir and up to #1352

Open
Tinter opened this issue Jul 6, 2020 · 11 comments
Open

Function to convert vector dir and up to #1352

Tinter opened this issue Jul 6, 2020 · 11 comments
Labels

Comments

@Tinter
Copy link
Contributor

Tinter commented Jul 6, 2020

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.

@Tinter Tinter added the Feature label Jul 6, 2020
@commy2
Copy link
Contributor

commy2 commented Jul 6, 2020

https://gist.github.com/commy2/d60b11fd38cf53f5c2ec02cda0dc3426

I never included it, because apparently BI made/was about to make their own function.

@commy2
Copy link
Contributor

commy2 commented Jul 6, 2020

I don't think you got _bank right.

@Tinter
Copy link
Contributor Author

Tinter commented Jul 7, 2020

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.

@Tinter
Copy link
Contributor Author

Tinter commented Jul 7, 2020

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.

@Tinter
Copy link
Contributor Author

Tinter commented Jul 7, 2020

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

@commy2
Copy link
Contributor

commy2 commented Jul 7, 2020

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.

@Tinter
Copy link
Contributor Author

Tinter commented Jul 7, 2020

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).

@Tinter
Copy link
Contributor Author

Tinter commented Jul 28, 2020

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
};

@commy2
Copy link
Contributor

commy2 commented Jul 29, 2020

Do we have the reverse?

@Tinter
Copy link
Contributor Author

Tinter commented Jul 30, 2020

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?

@commy2
Copy link
Contributor

commy2 commented Jul 30, 2020

Ah, I see. Missed the "complementary". That solves it then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants