• Re: Quaternions (was Re: Default signedness of 'plain' char.)

    From Lawrence D?Oliveiro@3:633/10 to All on Fri Aug 14 02:41:20 2026
    On Thu, 13 Aug 2026 18:50:05 -0700, Chris M. Thomasson wrote:

    Blender is pretty nice. But, its a bit large.

    It?s a lot smaller download than Autodesk Maya or proprietary
    alternatives like that.

    Anyway, matter not in a sense. Its a tool. And it fun to program in
    Python for it.

    I would say it caters to both sides of the brain -- artistic and
    technical. Skill in CG depends on a lot on developing capacity in
    both.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From BGB@3:633/10 to All on Thu Aug 13 23:07:01 2026
    On 8/13/2026 4:36 PM, Chris M. Thomasson wrote:
    On 8/13/2026 2:37 AM, BGB wrote:
    [...]

    Fwiw, I made this in OpenSCAD, its pretty nice. openscad Almost reminds
    me of povray...

    https://skfb.ly/oqQEV



    Similar syntax, as can be noted.


    A few limitations I have found, but still deciding on a strategy
    (whether to extend the language for my own uses, or make/use a different
    one that does the same basic thing but addresses a few of the
    weak-points; hopefully without creating new ones); or do nothing, and
    stick with the existing language as-is.

    Mostly works OK for both making parts to 3D print and also making basic
    3D models.

    Gives a lot of control and ability to edit things, but does depend some
    on thinking and mental math at times.


    As noted, in any case, I am not a fan of external dependencies, and particularly not large external dependencies.


    So, a "new" viewer, if implemented, would probably be a fairly simple
    program to do the CSG and display the result. May or may not have a
    built-in text editor, the other main option being to have a hot-reload key.

    May make sense to keep it backwards compatible with SCAD though, which
    leans more towards a modified superset rather than an entirely new language.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From BGB@3:633/10 to All on Thu Aug 13 23:47:27 2026
    On 8/13/2026 9:41 PM, Lawrence D?Oliveiro wrote:
    On Thu, 13 Aug 2026 18:50:05 -0700, Chris M. Thomasson wrote:

    Blender is pretty nice. But, its a bit large.

    It?s a lot smaller download than Autodesk Maya or proprietary
    alternatives like that.


    Better not to poke those with a stick IMO.

    They are specially designed to try to create vendor lock-in and then
    trick people into paying subscriptions to keep using the software; not
    worth it.


    Anyway, matter not in a sense. Its a tool. And it fun to program in
    Python for it.

    I would say it caters to both sides of the brain -- artistic and
    technical. Skill in CG depends on a lot on developing capacity in
    both.

    Yes, but still doesn't mean one wants to create a hard dependency on
    Blender or Python...


    Like, if you want a shovel...

    It doesn't matter that a Backhoe is smaller and cheaper than an Excavator.

    ...


    Sometimes, one just wants a few tools:
    A tool that converts a language to a 3D model in a specified format via
    a command-like or text-script so that it can be packaged up in some
    asset format (or output geometry as STL or "Wavefront OBJ" or similar);
    Another tool that allows viewing the 3D model, and launches quickly and doesn't require dealing with some cumbersome file selector dialog and
    import UI and similar;
    ...


    Like, you might just want to be like:
    Make tool;
    Associate file extension with tool;
    Double click;
    Done, view file;
    Close program when done looking at model, or have a reload hot-key for
    when one wants to edit the file (via something like Notepad).


    Or, say, like "Windows Photo Viewer" vs GIMP. Even if both have "open a
    photo and look at it" as features, they are still not really the same
    thing. Both serve very different roles in terms of purpose and UX.

    Or, by extension, "Microsoft 3D Viewer" vs Blender.
    3D Viewer likely being a closer analogy, but more obscure.


    And, no big central "do everything" programs needed or desired in many cases...

    Doesn't mean the big central program can't have it as well, but assuming
    the big central program is the end-all be-all, is seriously missing the
    point.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From BGB@3:633/10 to All on Thu Aug 13 23:50:16 2026
    On 8/11/2026 3:47 PM, Chris M. Thomasson wrote:
    On 8/11/2026 8:17 AM, James Kuyper wrote:
    On 2026-08-10 21:44, BGB wrote:
    On 8/10/2026 7:03 PM, James Kuyper wrote:
    On 2026-08-10 18:31, BGB wrote:
    Snipped section included my epic fail at trying to use traditional >>>> style
    mathematical notation in a Usenet post...

    It was bugging me, by implying the conjugate was a scalar, where
    no, the
    conjugate is not a scalar...

    I'm not sure what you're saying. As far as C is concerned. complex
    types
    are floating types (6.2.5p15), and therefore arithmetic types
    (6.2.5p23), and therefore scalar types (6.2.5p26) Therefore, a function >>>> that returns the conjugate of its argument would return a scalar type.

    I wrote:
    ÿÿÿ R^-1 = (R.r-R.i-R.j-R.k) / (R.r*R.r + R.i*R.i + R.j*R.j + R.k*R.k)

    The problem:
    ÿÿÿ (R.r-R.i-R.j-R.k)
    Should have been, say:
    ÿÿÿ (R.r - R.i*I - R.j*J - R.k*K)

    Which was bugging me, because either the former would be interpreted as
    meaning a scalar (or real-valued) result, or "R.i*R.i" as being
    negative, neither of which was true in the intended expression...

    I was confused because you were writing about complex numbers, mentioned
    that you had snipped some material, and then made a comment that I
    assumed, from context, was also about complex numbers. I did not realize
    that there was a context switch to quaternions inside the snipped
    material.
    In the unlikely event that that were added to C, quaternions would
    almost certainly be added as a new arithmetic (and therefore, scalar)
    type, by analogy with the complex types. I was unaware, until just now
    when I looked it up, that the real part of a quaternion is often
    referred to as it's scalar part.
    That's a little odd, because I'm one of the probably very few people
    here who've actually made practical use of quaternions. I had to deal
    with data about spacecraft orientation that was stored as a quaternion,
    and convert between quaternions and corresponding Euler angles and
    Rotation matrices. However, a quaternion library was part of the
    standard toolkit for that project, which makes sense.

    quaternion are very useful for such things. Avoiding gimbal lock?

    Among other things:
    No gimbal lock;
    Can LERP/SLERP;
    SLERP'ing between identity and a given rotation allows scaling the rotation; Can be used as a vector for angular velocity or angular inertia math;
    Can be multiplied for compound rotations (like with matrix math);

    Try to SLERP a matrix, and it may "rubber band" or have other weird
    glitches;
    Try to LERP Euler angles and the motion may end up going in some totally
    weird direction;
    ...

    If you use two of them (a "dual quaternion"), it is possible to express
    fairly arbitrary transforms (translation + rotation).

    Like, were pretty useful for doing something like a rigid-body physics
    engine, even if the physics engine itself turned out to not be very useful.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Fri Aug 14 04:59:19 2026
    On Thu, 13 Aug 2026 23:47:27 -0500, BGB wrote:

    On 8/13/2026 9:41 PM, Lawrence D?Oliveiro wrote:

    On Thu, 13 Aug 2026 18:50:05 -0700, Chris M. Thomasson wrote:

    Blender is pretty nice. But, its a bit large.

    It?s a lot smaller download than Autodesk Maya or proprietary
    alternatives like that.

    Better not to poke those with a stick IMO.

    They are specially designed to try to create vendor lock-in and then
    trick people into paying subscriptions to keep using the software;
    not worth it.

    They?re also specialist tools. They?ve given up being a complete
    workflow solution. So you need to spend even more money buying even
    more tools to get work done.

    No, they are not in a position to compete with open-source tools. All
    they?ve got is a multi-million-dollar publicity budget to tell
    everyone how wonderful they are. So they cater to those who are
    willing to swallow such things, and that?s enough to make them even
    more rich. They don?t need any more.

    Anyway, matter not in a sense. Its a tool. And it fun to program in
    Python for it.

    I would say it caters to both sides of the brain -- artistic and
    technical. Skill in CG depends on a lot on developing capacity in
    both.

    Yes, but still doesn't mean one wants to create a hard dependency on
    Blender or Python...

    The open-source world makes heavy use of code reuse. That?s why it?s
    such a productive place to be.

    You?re still thinking in Windows terms, aren?t you? Where everything
    has to be downloaded individually and installed manually, there is no integrated package manager to deal with the details for you.

    Sometimes, one just wants a few tools:
    A tool that converts a language to a 3D model in a specified format
    via a command-like or text-script so that it can be packaged up in
    some asset format (or output geometry as STL or "Wavefront OBJ" or
    similar); Another tool that allows viewing the 3D model, and
    launches quickly and doesn't require dealing with some cumbersome
    file selector dialog and import UI and similar; ...

    All doable.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Fri Aug 14 05:59:39 2026
    On Thu, 13 Aug 2026 23:50:16 -0500, BGB wrote:

    SLERP'ing between identity and a given rotation allows scaling the
    rotation;

    You can?t linearly interpolate the sines and cosines, though. If you
    want to do linear interpolation of the rotation angle, don?t you have
    to compute inverse sines/cosines, calculate new angles and then back
    again?

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From BGB@3:633/10 to All on Fri Aug 14 03:16:02 2026
    On 8/14/2026 12:59 AM, Lawrence D?Oliveiro wrote:
    On Thu, 13 Aug 2026 23:50:16 -0500, BGB wrote:

    SLERP'ing between identity and a given rotation allows scaling the
    rotation;

    You can?t linearly interpolate the sines and cosines, though. If you
    want to do linear interpolation of the rotation angle, don?t you have
    to compute inverse sines/cosines, calculate new angles and then back
    again?

    This is where it can get funny:
    While naive interpolation goes off the unit-sphere, re-normalizing the quaternion generally puts it back at around the position it would have
    been had one followed an arc over the surface of the hyper-sphere
    between these points (at least within +/- 180 degrees, and not
    necessarily at a uniform velocity if the distance is large).

    This is both more convenient and cheaper than using sines or cosines or
    trying to follow an arc. One can use them, but don't need to.

    More accuracy (and more uniform speed) is possible with a normalized
    LERP though by using a subdivision trick similar to that used for
    matrices if the points are further apart, though in this case it is a
    little cheaper, say:
    qnlerp(A,B,f)
    if(qdist2(A,B)<CUTOFF)
    return qnormalize(A*(1-f)+(B+f));
    C=qnormalize((A+B)*0.5);
    if(frac<0.5)
    return qnlerp(A,C,f*2);
    return qnlerp(C,B,f*2-1);


    Though, they still come up if moving to/from axis/angle or similar.

    As can be noted, multiplying rotations also effectively concatenates them.

    Can't really explain how it works...

    Granted, there are some weird cases that need to be worked around, but
    mostly it all "just sorta works"...



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Fri Aug 14 08:32:55 2026
    On Fri, 14 Aug 2026 03:16:02 -0500, BGB wrote:

    On 8/14/2026 12:59 AM, Lawrence D?Oliveiro wrote:

    On Thu, 13 Aug 2026 23:50:16 -0500, BGB wrote:

    SLERP'ing between identity and a given rotation allows scaling the
    rotation;

    You can?t linearly interpolate the sines and cosines, though. If
    you want to do linear interpolation of the rotation angle, don?t
    you have to compute inverse sines/cosines, calculate new angles and
    then back again?

    This is where it can get funny:
    While naive interpolation goes off the unit-sphere, re-normalizing
    the quaternion generally puts it back at around the position it
    would have been had one followed an arc over the surface of the
    hyper-sphere between these points (at least within +/- 180 degrees,
    and not necessarily at a uniform velocity if the distance is large).

    This is both more convenient and cheaper than using sines or cosines
    or trying to follow an arc. One can use them, but don't need to.

    Ha! Thanks for that.

    I was thinking in terms of inverting the formula for the quaternion
    for double the angle to get the one for half the angle. Probably
    involve square roots, which is still less computation than trig.

    After our previous exchange on quaternions, I was doing some
    experiments in Blender to see if I could patch up near-full-circle
    rotations in the wrong direction just by fiddling the quaternions, not
    by adding more key frames. Negating the W (cosine) component does flip
    the rotation direction, but the in-between rotation rate can go a bit
    wild unless you tweak one or two of the other components (i.e.
    contributions to the sine component) as well.

    As can be noted, multiplying rotations also effectively concatenates
    them.

    Can't really explain how it works...

    First of all, a quaternion consists of a vector (X, Y, Z) and scalar
    (W) part. The direction of the vector part gives the rotation axis,
    while its magnitude gives the sine of the half angle. The scalar part
    is the cosine of the half angle.

    Applying a rotation to a vector involves multiplying the quaternion by
    the vector. If this is just a special case of rotating a quaternion
    (i.e. nonzero scalar part), then it probably follows from that ...

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Fri Aug 14 12:17:54 2026
    On 8/13/2026 9:50 PM, BGB wrote:
    On 8/11/2026 3:47 PM, Chris M. Thomasson wrote:
    On 8/11/2026 8:17 AM, James Kuyper wrote:
    On 2026-08-10 21:44, BGB wrote:
    On 8/10/2026 7:03 PM, James Kuyper wrote:
    On 2026-08-10 18:31, BGB wrote:
    Snipped section included my epic fail at trying to use
    traditional
    style
    mathematical notation in a Usenet post...

    It was bugging me, by implying the conjugate was a scalar, where
    no, the
    conjugate is not a scalar...

    I'm not sure what you're saying. As far as C is concerned. complex
    types
    are floating types (6.2.5p15), and therefore arithmetic types
    (6.2.5p23), and therefore scalar types (6.2.5p26) Therefore, a
    function
    that returns the conjugate of its argument would return a scalar type. >>>>
    I wrote:
    ÿÿÿ R^-1 = (R.r-R.i-R.j-R.k) / (R.r*R.r + R.i*R.i + R.j*R.j + R.k*R.k) >>>>
    The problem:
    ÿÿÿ (R.r-R.i-R.j-R.k)
    Should have been, say:
    ÿÿÿ (R.r - R.i*I - R.j*J - R.k*K)

    Which was bugging me, because either the former would be interpreted as >>>> meaning a scalar (or real-valued) result, or "R.i*R.i" as being
    negative, neither of which was true in the intended expression...

    I was confused because you were writing about complex numbers, mentioned >>> that you had snipped some material, and then made a comment that I
    assumed, from context, was also about complex numbers. I did not realize >>> that there was a context switch to quaternions inside the snipped
    material.
    In the unlikely event that that were added to C, quaternions would
    almost certainly be added as a new arithmetic (and therefore, scalar)
    type, by analogy with the complex types. I was unaware, until just now
    when I looked it up, that the real part of a quaternion is often
    referred to as it's scalar part.
    That's a little odd, because I'm one of the probably very few people
    here who've actually made practical use of quaternions. I had to deal
    with data about spacecraft orientation that was stored as a quaternion,
    and convert between quaternions and corresponding Euler angles and
    Rotation matrices. However, a quaternion library was part of the
    standard toolkit for that project, which makes sense.

    quaternion are very useful for such things. Avoiding gimbal lock?

    Among other things:
    No gimbal lock;
    Can LERP/SLERP;
    SLERP'ing between identity and a given rotation allows scaling the
    rotation;
    Can be used as a vector for angular velocity or angular inertia math;
    Can be multiplied for compound rotations (like with matrix math);

    Try to SLERP a matrix, and it may "rubber band" or have other weird glitches;
    Try to LERP Euler angles and the motion may end up going in some totally weird direction;
    ...

    If you use two of them (a "dual quaternion"), it is possible to express fairly arbitrary transforms (translation + rotation).

    Like, were pretty useful for doing something like a rigid-body physics engine, even if the physics engine itself turned out to not be very useful.



    Its interesting. Fwiw, I can get all of the bone matrices to work in my shaders without using quaternion. But, that just the way I coded it up.
    List animations, play them, etc. In my experimental engine. Have you
    taken a look at the assimp lib yet? Oh its helps!

    Iirc, GLM has a glm::quat... :^)

    Note it, read it, want it... ;^D

    https://github.com/g-truc/glm

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Fri Aug 14 12:36:25 2026
    On 8/13/2026 10:59 PM, Lawrence D?Oliveiro wrote:
    On Thu, 13 Aug 2026 23:50:16 -0500, BGB wrote:

    SLERP'ing between identity and a given rotation allows scaling the
    rotation;

    You can?t linearly interpolate the sines and cosines, though. If you
    want to do linear interpolation of the rotation angle, don?t you have
    to compute inverse sines/cosines, calculate new angles and then back
    again?

    To interpolate the rotation angle? Something simple, linear:

    // typed in the newsreader sorry for any typos

    ________________________
    unsigned long n = 42; // granularity and iter all in one...

    float angle_min = 0;
    float angle_max = PI/2;
    float angle_dif = angle_max - angle_min;

    float normal_base = 1.f/n

    for (unsigned long i = 0; i < n; ++i)
    {
    float normal = normal_base * i;
    float angle = angle_min + angle_dif * normal;

    float x0 = cos(angle);
    float y0 = sin(angle);

    // (x0, y0) as normalized here

    // render line from (0, 0) to (x0, y0)...
    }
    ________________________

    Now, this missed normal equaling 1 during iteration... We can do two
    things here if that is in your requirements. Alter the base, or over
    iterate by one. The prior needs to resist division by zero.

    float normal_base = (n > 1) ? 1.f/(n-1) : 0.f;
    for (unsigned long i = 0; i < n; ++i) { ... }


    vs...

    float normal_base = 1.f/n;
    for (unsigned long i = 0; i <= n; ++i) { ... }

    One of the methods over extend i such that i can equal n. Beware of that
    in case you are using i to index into an array or something...

    So, we need to ponder on the i-1 for the normal_base, or the over
    iterate if we want normal in the loop to reach angle_max. Fair enough?

    ;^)

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Sat Aug 15 03:16:38 2026
    On Fri, 14 Aug 2026 12:36:25 -0700, Chris M. Thomasson wrote:

    float angle_min = 0;
    float angle_max = PI/2;
    float angle_dif = angle_max - angle_min;

    float normal_base = 1.f/n

    for (unsigned long i = 0; i < n; ++i)
    {
    float normal = normal_base * i;
    float angle = angle_min + angle_dif * normal;

    float x0 = cos(angle);
    float y0 = sin(angle);

    // (x0, y0) as normalized here

    // render line from (0, 0) to (x0, y0)...
    }

    But the quaternion doesn?t directly give you the angle to begin with,
    you will need to do an inverse trig computation to get it. And then do
    the above trig calls for every segment.

    I just wondered if there was a way to go straight from cos/sin of an
    angle to cos/sin of fractions of that angle ... I think there is.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Fri Aug 14 22:38:37 2026
    On 8/14/2026 8:16 PM, Lawrence D?Oliveiro wrote:
    On Fri, 14 Aug 2026 12:36:25 -0700, Chris M. Thomasson wrote:

    float angle_min = 0;
    float angle_max = PI/2;
    float angle_dif = angle_max - angle_min;

    float normal_base = 1.f/n

    for (unsigned long i = 0; i < n; ++i)
    {
    float normal = normal_base * i;
    float angle = angle_min + angle_dif * normal;

    float x0 = cos(angle);
    float y0 = sin(angle);

    // (x0, y0) as normalized here

    // render line from (0, 0) to (x0, y0)...
    }

    But the quaternion doesn?t directly give you the angle to begin with,
    you will need to do an inverse trig computation to get it. And then do
    the above trig calls for every segment.

    Or start from the angles and create a quat?


    I just wondered if there was a way to go straight from cos/sin of an
    angle to cos/sin of fractions of that angle ... I think there is.

    Depends on what angles you are looking for?


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Sun Aug 16 00:08:27 2026
    On Fri, 14 Aug 2026 22:38:37 -0700, Chris M. Thomasson wrote:

    Or start from the angles and create a quat?

    You mean, carry the angle around as a separate quantity, in addition
    to the quaternion representing i?

    Depends on what angles you are looking for?

    The angle represented by the quaternion.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)