discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How to translate 3 vector axis to a camera viewpoint?

A
arnholm@arnholm.org
Fri, Feb 3, 2017 8:26 AM

On 2017-02-02 20:58, doug moen wrote:

Ronaldo said: "Euler angles really sucks. It is the worst system to
represent rotations."

Haha, that's a pretty strong statement. I am considering to use
quaternions to represent 3D rotations in my new geometry engine. The
upside is no gimbal lock, normalization, and the slerp function, which
are real benefits. The downside is that the 4 numbers stored in a
quaternion are incomprehensible to ordinary humans, so you need to use
library functions to manipulate quaternions. Euler angles are at least
easier to understand.

Describing the position and orientation of e.g. a camera in this case
becomes awkward if you consider it as "3D rotations". It is well defined
as a local coordinate system: A location for the location origin and 3
direction vectors (3 cosines each) for the local axes, all relative to
the global coordinate system. All this again is simply expressed as a
4x4 homogenous transformation matrix, as in the multmatrix command.

To modify the camera locaton and/or orientation you pre- or
post-multiply (depending on the wanted effect) with another matrix to
get a new local coordinate system.

Carste Arnholm

On 2017-02-02 20:58, doug moen wrote: > Ronaldo said: "Euler angles really sucks. It is the worst system to > represent rotations." > > Haha, that's a pretty strong statement. I am considering to use > quaternions to represent 3D rotations in my new geometry engine. The > upside is no gimbal lock, normalization, and the slerp function, which > are real benefits. The downside is that the 4 numbers stored in a > quaternion are incomprehensible to ordinary humans, so you need to use > library functions to manipulate quaternions. Euler angles are at least > easier to understand. Describing the position and orientation of e.g. a camera in this case becomes awkward if you consider it as "3D rotations". It is well defined as a local coordinate system: A location for the location origin and 3 direction vectors (3 cosines each) for the local axes, all relative to the global coordinate system. All this again is simply expressed as a 4x4 homogenous transformation matrix, as in the multmatrix command. To modify the camera locaton and/or orientation you pre- or post-multiply (depending on the wanted effect) with another matrix to get a new local coordinate system. Carste Arnholm
R
Ronaldo
Fri, Feb 3, 2017 2:28 PM

doug.moen wrote

Ronaldo said: "Euler angles really sucks. It is the worst system to
represent rotations."

Haha, that's a pretty strong statement. I am considering to use
quaternions
to represent 3D rotations in my new geometry engine. The upside is no
gimbal lock, normalization, and the slerp function, which are real
benefits. The downside is that the 4 numbers stored in a quaternion are
incomprehensible to ordinary humans, so you need to use library functions
to manipulate quaternions. Euler angles are at least easier to understand.

Let me clarify my statement. Euler angles is the one of the worst systems to
represent rotations in a API. Quaternions would be even worst.

I don't care which representation is used internally. It may be quaternions,
Euler angles, whatever - what is better from the system point of view. But
for the user, that means, in the language, neither one are acceptable. At
least for me, with a no-complex-numbers mind neither a pilot driver's
licence. I live with the feet on earth, a 2D surface. I can turn right or
left. I can't fly. To work with Euler angles means to compose 3 basic
rotations. In my mind, I can compose 2 at most without twisting it. The most
natural way to represent a rotation for me would be a direction and an
angle. I can't see which rotation is represented in a rotation matrix the
same way I can't see it in a quaternion. These are mathematical
representations and not modeling tools! That is my question: which is the
best modeling means to represent rotations?

BTW, unitary coordinate system change is a rotation.

--
View this message in context: http://forum.openscad.org/How-to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

doug.moen wrote > Ronaldo said: "Euler angles really sucks. It is the worst system to > represent rotations." > > Haha, that's a pretty strong statement. I am considering to use > quaternions > to represent 3D rotations in my new geometry engine. The upside is no > gimbal lock, normalization, and the slerp function, which are real > benefits. The downside is that the 4 numbers stored in a quaternion are > incomprehensible to ordinary humans, so you need to use library functions > to manipulate quaternions. Euler angles are at least easier to understand. Let me clarify my statement. Euler angles is the one of the worst systems to represent rotations in a API. Quaternions would be even worst. I don't care which representation is used internally. It may be quaternions, Euler angles, whatever - what is better from the system point of view. But for the user, that means, in the language, neither one are acceptable. At least for me, with a no-complex-numbers mind neither a pilot driver's licence. I live with the feet on earth, a 2D surface. I can turn right or left. I can't fly. To work with Euler angles means to compose 3 basic rotations. In my mind, I can compose 2 at most without twisting it. The most natural way to represent a rotation for me would be a direction and an angle. I can't see which rotation is represented in a rotation matrix the same way I can't see it in a quaternion. These are mathematical representations and not modeling tools! That is my question: which is the best modeling means to represent rotations? BTW, unitary coordinate system change is a rotation. -- View this message in context: http://forum.openscad.org/How-to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Fri, Feb 3, 2017 4:29 PM

Ronaldo said: "for the user, in the language ... which is the best modeling
means to represent rotations?"

Let's represent a 3D rotation as an abstract data type, call it Q. As a
user you don't care about the internal representation.

Construction of a Q:

q = q_from_axis_and_angle(axis, angle) -- axis is a [x,y,z] vector
q = q_from_directions(forward_direction, upward_direction)
q = q_from_xyz_angles(angles)
From Euler angles, using the OpenSCAD convention.
q = q_from_rotation_matrix(matrix)
q = q_rotation_to(from_vector, to_vector)
The shortest arc quaternion that rotates from the 'from' direction
to the 'to' direction.
q = q_slerp(q1, q2, t)
Interpolates along the shortest spherical path
between the rotational positions q1 and q2.
The value t should be between 0 and 1.
https://en.wikipedia.org/wiki/Slerp

Accessing the data in a Q:

[axis, angle] = q_to_axis_and_angle(q)
[forward_direction, upward_direction] = q_to_directions(q)
[xangle,yangle,zangle] = q_to_xyz_angles(q)
rotation_matrix = q_to_rotation_matrix(q)

Applying a Q:

vector = q_rotate(q, vector)
matrix = q_rotate(q, matrix)
rotate(q) shape -- a possible extension to OpenSCAD

Implementing this as an OpenSCAD library, I'd represent a Q as a
quaternion, specifically as a 4-vector, [x,y,z,s], so that's what you'd see
if you echo'ed a Q. There are other possible internal representations for a
Q, but the quaternion representation would be the most efficient. The
internal representation shouldn't matter to users: you would not normally
attempt to construct a Q directly, you'd only use the library functions.

On 3 February 2017 at 09:28, Ronaldo rcmpersiano@gmail.com wrote:

doug.moen wrote

Ronaldo said: "Euler angles really sucks. It is the worst system to
represent rotations."

Haha, that's a pretty strong statement. I am considering to use
quaternions
to represent 3D rotations in my new geometry engine. The upside is no
gimbal lock, normalization, and the slerp function, which are real
benefits. The downside is that the 4 numbers stored in a quaternion are
incomprehensible to ordinary humans, so you need to use library functions
to manipulate quaternions. Euler angles are at least easier to

understand.

Let me clarify my statement. Euler angles is the one of the worst systems
to
represent rotations in a API. Quaternions would be even worst.

I don't care which representation is used internally. It may be
quaternions,
Euler angles, whatever - what is better from the system point of view. But
for the user, that means, in the language, neither one are acceptable. At
least for me, with a no-complex-numbers mind neither a pilot driver's
licence. I live with the feet on earth, a 2D surface. I can turn right or
left. I can't fly. To work with Euler angles means to compose 3 basic
rotations. In my mind, I can compose 2 at most without twisting it. The
most
natural way to represent a rotation for me would be a direction and an
angle. I can't see which rotation is represented in a rotation matrix the
same way I can't see it in a quaternion. These are mathematical
representations and not modeling tools! That is my question: which is the
best modeling means to represent rotations?

BTW, unitary coordinate system change is a rotation.

--
View this message in context: http://forum.openscad.org/How-
to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Ronaldo said: "for the user, in the language ... which is the best modeling means to represent rotations?" Let's represent a 3D rotation as an abstract data type, call it Q. As a user you don't care about the internal representation. Construction of a Q: q = q_from_axis_and_angle(axis, angle) -- axis is a [x,y,z] vector q = q_from_directions(forward_direction, upward_direction) q = q_from_xyz_angles(angles) From Euler angles, using the OpenSCAD convention. q = q_from_rotation_matrix(matrix) q = q_rotation_to(from_vector, to_vector) The shortest arc quaternion that rotates from the 'from' direction to the 'to' direction. q = q_slerp(q1, q2, t) Interpolates along the shortest spherical path between the rotational positions q1 and q2. The value t should be between 0 and 1. https://en.wikipedia.org/wiki/Slerp Accessing the data in a Q: [axis, angle] = q_to_axis_and_angle(q) [forward_direction, upward_direction] = q_to_directions(q) [xangle,yangle,zangle] = q_to_xyz_angles(q) rotation_matrix = q_to_rotation_matrix(q) Applying a Q: vector = q_rotate(q, vector) matrix = q_rotate(q, matrix) rotate(q) shape -- a possible extension to OpenSCAD Implementing this as an OpenSCAD library, I'd represent a Q as a quaternion, specifically as a 4-vector, [x,y,z,s], so that's what you'd see if you echo'ed a Q. There are other possible internal representations for a Q, but the quaternion representation would be the most efficient. The internal representation shouldn't matter to users: you would not normally attempt to construct a Q directly, you'd only use the library functions. On 3 February 2017 at 09:28, Ronaldo <rcmpersiano@gmail.com> wrote: > doug.moen wrote > > Ronaldo said: "Euler angles really sucks. It is the worst system to > > represent rotations." > > > > Haha, that's a pretty strong statement. I am considering to use > > quaternions > > to represent 3D rotations in my new geometry engine. The upside is no > > gimbal lock, normalization, and the slerp function, which are real > > benefits. The downside is that the 4 numbers stored in a quaternion are > > incomprehensible to ordinary humans, so you need to use library functions > > to manipulate quaternions. Euler angles are at least easier to > understand. > > Let me clarify my statement. Euler angles is the one of the worst systems > to > represent rotations in a API. Quaternions would be even worst. > > I don't care which representation is used internally. It may be > quaternions, > Euler angles, whatever - what is better from the system point of view. But > for the user, that means, in the language, neither one are acceptable. At > least for me, with a no-complex-numbers mind neither a pilot driver's > licence. I live with the feet on earth, a 2D surface. I can turn right or > left. I can't fly. To work with Euler angles means to compose 3 basic > rotations. In my mind, I can compose 2 at most without twisting it. The > most > natural way to represent a rotation for me would be a direction and an > angle. I can't see which rotation is represented in a rotation matrix the > same way I can't see it in a quaternion. These are mathematical > representations and not modeling tools! That is my question: which is the > best modeling means to represent rotations? > > BTW, unitary coordinate system change is a rotation. > > > > > > -- > View this message in context: http://forum.openscad.org/How- > to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >
DM
doug moen
Fri, Feb 3, 2017 7:22 PM

Adrian said:
So, I have three orthogonal vectors and I wish to set my viewport to the
'top
view' of these vectors.  How would I go about doing that?  I'm thinking that
I would have to modify the $vpr variable, but how?

The QT5 quaternion package has a function that constructs a quaternion from
3 orthonormal axes. So if we add
q_from_axes(xaxis, yaxis, zaxis)
to my proposed Q library, then Adrian could probably write
$vpr = q_to_xyz_angles(q_from_axes(xaxis, yaxis, zaxis));

I haven't actually started to write any quaternion code yet. But there are
lots of open source packages to copy from, and the QT5 code could be
starting point. Eg,

https://github.com/RSATom/Qt/blob/master/qtbase/src/gui/math3d/qquaternion.h
https://github.com/RSATom/Qt/blob/master/qtbase/src/gui/math3d/qquaternion.cpp

On 3 February 2017 at 11:29, doug moen doug@moens.org wrote:

Ronaldo said: "for the user, in the language ... which is the best
modeling means to represent rotations?"

Let's represent a 3D rotation as an abstract data type, call it Q. As a
user you don't care about the internal representation.

Construction of a Q:

q = q_from_axis_and_angle(axis, angle) -- axis is a [x,y,z] vector
q = q_from_directions(forward_direction, upward_direction)
q = q_from_xyz_angles(angles)
From Euler angles, using the OpenSCAD convention.
q = q_from_rotation_matrix(matrix)
q = q_rotation_to(from_vector, to_vector)
The shortest arc quaternion that rotates from the 'from' direction
to the 'to' direction.
q = q_slerp(q1, q2, t)
Interpolates along the shortest spherical path
between the rotational positions q1 and q2.
The value t should be between 0 and 1.
https://en.wikipedia.org/wiki/Slerp

Accessing the data in a Q:

[axis, angle] = q_to_axis_and_angle(q)
[forward_direction, upward_direction] = q_to_directions(q)
[xangle,yangle,zangle] = q_to_xyz_angles(q)
rotation_matrix = q_to_rotation_matrix(q)

Applying a Q:

vector = q_rotate(q, vector)
matrix = q_rotate(q, matrix)
rotate(q) shape -- a possible extension to OpenSCAD

Implementing this as an OpenSCAD library, I'd represent a Q as a
quaternion, specifically as a 4-vector, [x,y,z,s], so that's what you'd see
if you echo'ed a Q. There are other possible internal representations for a
Q, but the quaternion representation would be the most efficient. The
internal representation shouldn't matter to users: you would not normally
attempt to construct a Q directly, you'd only use the library functions.

On 3 February 2017 at 09:28, Ronaldo rcmpersiano@gmail.com wrote:

doug.moen wrote

Ronaldo said: "Euler angles really sucks. It is the worst system to
represent rotations."

Haha, that's a pretty strong statement. I am considering to use
quaternions
to represent 3D rotations in my new geometry engine. The upside is no
gimbal lock, normalization, and the slerp function, which are real
benefits. The downside is that the 4 numbers stored in a quaternion are
incomprehensible to ordinary humans, so you need to use library

functions

to manipulate quaternions. Euler angles are at least easier to

understand.

Let me clarify my statement. Euler angles is the one of the worst systems
to
represent rotations in a API. Quaternions would be even worst.

I don't care which representation is used internally. It may be
quaternions,
Euler angles, whatever - what is better from the system point of view. But
for the user, that means, in the language, neither one are acceptable. At
least for me, with a no-complex-numbers mind neither a pilot driver's
licence. I live with the feet on earth, a 2D surface. I can turn right or
left. I can't fly. To work with Euler angles means to compose 3 basic
rotations. In my mind, I can compose 2 at most without twisting it. The
most
natural way to represent a rotation for me would be a direction and an
angle. I can't see which rotation is represented in a rotation matrix the
same way I can't see it in a quaternion. These are mathematical
representations and not modeling tools! That is my question: which is the
best modeling means to represent rotations?

BTW, unitary coordinate system change is a rotation.

--
View this message in context: http://forum.openscad.org/How-
to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Adrian said: So, I have three orthogonal vectors and I wish to set my viewport to the 'top view' of these vectors. How would I go about doing that? I'm thinking that I would have to modify the $vpr variable, but how? The QT5 quaternion package has a function that constructs a quaternion from 3 orthonormal axes. So if we add q_from_axes(xaxis, yaxis, zaxis) to my proposed Q library, then Adrian could probably write $vpr = q_to_xyz_angles(q_from_axes(xaxis, yaxis, zaxis)); I haven't actually started to write any quaternion code yet. But there are lots of open source packages to copy from, and the QT5 code could be starting point. Eg, https://github.com/RSATom/Qt/blob/master/qtbase/src/gui/math3d/qquaternion.h https://github.com/RSATom/Qt/blob/master/qtbase/src/gui/math3d/qquaternion.cpp On 3 February 2017 at 11:29, doug moen <doug@moens.org> wrote: > Ronaldo said: "for the user, in the language ... which is the best > modeling means to represent rotations?" > > Let's represent a 3D rotation as an abstract data type, call it Q. As a > user you don't care about the internal representation. > > Construction of a Q: > > q = q_from_axis_and_angle(axis, angle) -- axis is a [x,y,z] vector > q = q_from_directions(forward_direction, upward_direction) > q = q_from_xyz_angles(angles) > From Euler angles, using the OpenSCAD convention. > q = q_from_rotation_matrix(matrix) > q = q_rotation_to(from_vector, to_vector) > The shortest arc quaternion that rotates from the 'from' direction > to the 'to' direction. > q = q_slerp(q1, q2, t) > Interpolates along the shortest spherical path > between the rotational positions q1 and q2. > The value t should be between 0 and 1. > https://en.wikipedia.org/wiki/Slerp > > Accessing the data in a Q: > > [axis, angle] = q_to_axis_and_angle(q) > [forward_direction, upward_direction] = q_to_directions(q) > [xangle,yangle,zangle] = q_to_xyz_angles(q) > rotation_matrix = q_to_rotation_matrix(q) > > Applying a Q: > > vector = q_rotate(q, vector) > matrix = q_rotate(q, matrix) > rotate(q) shape -- a possible extension to OpenSCAD > > Implementing this as an OpenSCAD library, I'd represent a Q as a > quaternion, specifically as a 4-vector, [x,y,z,s], so that's what you'd see > if you echo'ed a Q. There are other possible internal representations for a > Q, but the quaternion representation would be the most efficient. The > internal representation shouldn't matter to users: you would not normally > attempt to construct a Q directly, you'd only use the library functions. > > On 3 February 2017 at 09:28, Ronaldo <rcmpersiano@gmail.com> wrote: > >> doug.moen wrote >> > Ronaldo said: "Euler angles really sucks. It is the worst system to >> > represent rotations." >> > >> > Haha, that's a pretty strong statement. I am considering to use >> > quaternions >> > to represent 3D rotations in my new geometry engine. The upside is no >> > gimbal lock, normalization, and the slerp function, which are real >> > benefits. The downside is that the 4 numbers stored in a quaternion are >> > incomprehensible to ordinary humans, so you need to use library >> functions >> > to manipulate quaternions. Euler angles are at least easier to >> understand. >> >> Let me clarify my statement. Euler angles is the one of the worst systems >> to >> represent rotations in a API. Quaternions would be even worst. >> >> I don't care which representation is used internally. It may be >> quaternions, >> Euler angles, whatever - what is better from the system point of view. But >> for the user, that means, in the language, neither one are acceptable. At >> least for me, with a no-complex-numbers mind neither a pilot driver's >> licence. I live with the feet on earth, a 2D surface. I can turn right or >> left. I can't fly. To work with Euler angles means to compose 3 basic >> rotations. In my mind, I can compose 2 at most without twisting it. The >> most >> natural way to represent a rotation for me would be a direction and an >> angle. I can't see which rotation is represented in a rotation matrix the >> same way I can't see it in a quaternion. These are mathematical >> representations and not modeling tools! That is my question: which is the >> best modeling means to represent rotations? >> >> BTW, unitary coordinate system change is a rotation. >> >> >> >> >> >> -- >> View this message in context: http://forum.openscad.org/How- >> to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20303.html >> Sent from the OpenSCAD mailing list archive at Nabble.com. >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >> >> >
R
Ronaldo
Mon, Feb 6, 2017 2:47 PM

dough,

I like the idea of having conversion functions from one rotation
representations to the others. They are simple enough to be written in
OpenSCAD and be efficient. They should be part of a OpenSCAD standard
library.

I have however doubts about using quaternions as an internal representation
in OpenSCAD and have an abstract object rotation to be used as argument of
rotate() for instance. The main advantage of quaternions seems to be in
applications where a long sequence of small rotations should be applied. In
this case, troubles due to numerical errors are easier to correct by
normalization of quaternions than normalization of a rotation matrix. This
advantage is the reason of its success in animation. But I don't see
OpenSCAD incorporating real animation resources in a mid term. The only
OpenSCAD operation I see now that could benefit from this quaternion
superiority is sweep (rotate_extrude, linear_extrude with twist and sweep
operations similar to the Oskar Linde's one) and even so if we need a very
very refined discretization. I don't know how it is coded in C, but I don't
see any presence of approximation errors with rotate_extrude with $fn=1000.

An other point to consider is time expended in operations with quaternions.
Composing quaternion rotations is faster than rotation matrix
multiplications. But applying quaternions to rotate points is quite slower.
So, in an application with a complex model, it is recommended to convert the
quaternion rotation to a matrix rotation before rotating points. It seems to
me that typical OpenSCAD codes will not benefit from the composing speed of
quaternions.

Gimbal lock is an issue just to the representation by Euler angles and
quaternions are equivalent to the other representations in this aspect.

So, I would like you to know which is the benefits you see in using
quaternions over other representations (excluding Euler angles) in the
context of OpenSCAD codes?

--
View this message in context: http://forum.openscad.org/How-to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20344.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

dough, I like the idea of having conversion functions from one rotation representations to the others. They are simple enough to be written in OpenSCAD and be efficient. They should be part of a OpenSCAD standard library. I have however doubts about using quaternions as an internal representation in OpenSCAD and have an abstract object rotation to be used as argument of rotate() for instance. The main advantage of quaternions seems to be in applications where a long sequence of small rotations should be applied. In this case, troubles due to numerical errors are easier to correct by normalization of quaternions than normalization of a rotation matrix. This advantage is the reason of its success in animation. But I don't see OpenSCAD incorporating real animation resources in a mid term. The only OpenSCAD operation I see now that could benefit from this quaternion superiority is sweep (rotate_extrude, linear_extrude with twist and sweep operations similar to the Oskar Linde's one) and even so if we need a very very refined discretization. I don't know how it is coded in C, but I don't see any presence of approximation errors with rotate_extrude with $fn=1000. An other point to consider is time expended in operations with quaternions. Composing quaternion rotations is faster than rotation matrix multiplications. But applying quaternions to rotate points is quite slower. So, in an application with a complex model, it is recommended to convert the quaternion rotation to a matrix rotation before rotating points. It seems to me that typical OpenSCAD codes will not benefit from the composing speed of quaternions. Gimbal lock is an issue just to the representation by Euler angles and quaternions are equivalent to the other representations in this aspect. So, I would like you to know which is the benefits you see in using quaternions over other representations (excluding Euler angles) in the context of OpenSCAD codes? -- View this message in context: http://forum.openscad.org/How-to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20344.html Sent from the OpenSCAD mailing list archive at Nabble.com.
DM
doug moen
Mon, Feb 6, 2017 6:17 PM

Ronaldo said "applying quaternions to rotate points is quite slower."

I didn't know this. Rotating a point using quaternions is 24
multiplications, vs 9 multiplications (using a 3x3 rotation matrix) or 16
multiplications (using a 4x4 rotation matrix).

If you are performing a large number of these quaternion operations during
each frame of a video game, then it could be a significant performance hit,
relative to using a 3x3 rotation matrix. Especially since I suspect GPUs
have hardware support for matrix multiplication. In the context of game
programming, you want to have both rotation matrixes and quaternions
available as tools.

In OpenSCAD, execution time of a script is usually not an issue, it's
usually CGAL operations on complex objects that limit performance. The
evaluator is extremely slow compared to C, so if the performance of the
rotation library does turn out to be important, then hard coding the
operations in C is going to have a much bigger impact than the actual
representation chosen for 3D rotations.

The other general representation that makes sense to me is a 3x3 rotation
matrix. A few of the operations I specified would require conversion
to/from quaternions to implement, so you'd still like a quaternion library
to implement those operations: q_from_axis_and_angle(), q_rotation_to(from,
to) and q_slerp(q1,q2,t). Slerp is quite useful for animation.

General purpose 3D graphics libraries provide both matrices and
quaternions, so I guess the right answer is to support both.

On 6 February 2017 at 09:47, Ronaldo rcmpersiano@gmail.com wrote:

dough,

I like the idea of having conversion functions from one rotation
representations to the others. They are simple enough to be written in
OpenSCAD and be efficient. They should be part of a OpenSCAD standard
library.

I have however doubts about using quaternions as an internal representation
in OpenSCAD and have an abstract object rotation to be used as argument of
rotate() for instance. The main advantage of quaternions seems to be in
applications where a long sequence of small rotations should be applied. In
this case, troubles due to numerical errors are easier to correct by
normalization of quaternions than normalization of a rotation matrix. This
advantage is the reason of its success in animation. But I don't see
OpenSCAD incorporating real animation resources in a mid term. The only
OpenSCAD operation I see now that could benefit from this quaternion
superiority is sweep (rotate_extrude, linear_extrude with twist and sweep
operations similar to the Oskar Linde's one) and even so if we need a very
very refined discretization. I don't know how it is coded in C, but I don't
see any presence of approximation errors with rotate_extrude with $fn=1000.

An other point to consider is time expended in operations with quaternions.
Composing quaternion rotations is faster than rotation matrix
multiplications. But applying quaternions to rotate points is quite slower.
So, in an application with a complex model, it is recommended to convert
the
quaternion rotation to a matrix rotation before rotating points. It seems
to
me that typical OpenSCAD codes will not benefit from the composing speed of
quaternions.

Gimbal lock is an issue just to the representation by Euler angles and
quaternions are equivalent to the other representations in this aspect.

So, I would like you to know which is the benefits you see in using
quaternions over other representations (excluding Euler angles) in the
context of OpenSCAD codes?

--
View this message in context: http://forum.openscad.org/How-
to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20344.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Ronaldo said "applying quaternions to rotate points is quite slower." I didn't know this. Rotating a point using quaternions is 24 multiplications, vs 9 multiplications (using a 3x3 rotation matrix) or 16 multiplications (using a 4x4 rotation matrix). If you are performing a large number of these quaternion operations during each frame of a video game, then it could be a significant performance hit, relative to using a 3x3 rotation matrix. Especially since I suspect GPUs have hardware support for matrix multiplication. In the context of game programming, you want to have both rotation matrixes and quaternions available as tools. In OpenSCAD, execution time of a script is *usually* not an issue, it's usually CGAL operations on complex objects that limit performance. The evaluator is extremely slow compared to C, so if the performance of the rotation library does turn out to be important, then hard coding the operations in C is going to have a much bigger impact than the actual representation chosen for 3D rotations. The other general representation that makes sense to me is a 3x3 rotation matrix. A few of the operations I specified would require conversion to/from quaternions to implement, so you'd still like a quaternion library to implement those operations: q_from_axis_and_angle(), q_rotation_to(from, to) and q_slerp(q1,q2,t). Slerp is quite useful for animation. General purpose 3D graphics libraries provide both matrices and quaternions, so I guess the right answer is to support both. On 6 February 2017 at 09:47, Ronaldo <rcmpersiano@gmail.com> wrote: > dough, > > I like the idea of having conversion functions from one rotation > representations to the others. They are simple enough to be written in > OpenSCAD and be efficient. They should be part of a OpenSCAD standard > library. > > I have however doubts about using quaternions as an internal representation > in OpenSCAD and have an abstract object rotation to be used as argument of > rotate() for instance. The main advantage of quaternions seems to be in > applications where a long sequence of small rotations should be applied. In > this case, troubles due to numerical errors are easier to correct by > normalization of quaternions than normalization of a rotation matrix. This > advantage is the reason of its success in animation. But I don't see > OpenSCAD incorporating real animation resources in a mid term. The only > OpenSCAD operation I see now that could benefit from this quaternion > superiority is sweep (rotate_extrude, linear_extrude with twist and sweep > operations similar to the Oskar Linde's one) and even so if we need a very > very refined discretization. I don't know how it is coded in C, but I don't > see any presence of approximation errors with rotate_extrude with $fn=1000. > > An other point to consider is time expended in operations with quaternions. > Composing quaternion rotations is faster than rotation matrix > multiplications. But applying quaternions to rotate points is quite slower. > So, in an application with a complex model, it is recommended to convert > the > quaternion rotation to a matrix rotation before rotating points. It seems > to > me that typical OpenSCAD codes will not benefit from the composing speed of > quaternions. > > Gimbal lock is an issue just to the representation by Euler angles and > quaternions are equivalent to the other representations in this aspect. > > So, I would like you to know which is the benefits you see in using > quaternions over other representations (excluding Euler angles) in the > context of OpenSCAD codes? > > > > > > -- > View this message in context: http://forum.openscad.org/How- > to-translate-3-vector-axis-to-a-camera-viewpoint-tp20289p20344.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > >