Truthfully it isn't really that special, but it is a bit cancerous as I only have atan() and not atan2()...
What's special about it is every other function I see seems to be intrinsic with 1 axis needing a sqrt() to manage singularities,
where what I'm looking to achieve is an extrinsic function that shouldn't have to care about singularities.

If it helps with anything, converting to mtx33 before euler might help in singularity management, as mtx33 is extrinsic by default.
(I've just recently learned a mtx33 was just an over-glorified semi-scalar NBT vector)

I'm not a mathematician though, so I'm not sure how much help that'll actually be...
but I AM certain the output code can be done without the need of managing singularities:

atan2(x,y),
atan2(x,y),
atan2(x,y)

instead of:

atan2(x,y),      # X pitch
atan2(x,sqrt()), # Y yaw
atan2(x,y)       # Z roll

as this causes 1 axis (yaw in this case) to lock up and not move >90 degrees without intrinsic measures applied to X and Z.

Also yes, I'm just using atan2 as an example here as I actually can't use it in what I'm doing...

There actually isn't a tag for what I'm doing as while it involves XML, it's actually somewhat C-like,
so in this case I'm requesting python just because it's easier to follow. :P

I can translate that to this:

<eval expr="eulerX = atan(Y/X)" display_error="false" display_result="false" comment=""/>

+1 if you actually know what I'm working with (irrelevant)

Is there anything that would fit what I need??

Recommended Answers

Why can't you use atan2? It appears to be in Python today.

I'm reading https://www.w3schools.com/python/ref_math_atan2.asp

Jump to Post

I would be guessing what this eval tag is. Maybe you are on some Python from years ago or something else. As it stands I can't see what's stopping you from using Python's math functions.

As to the mark solved, one wrong click and that happens.

Jump to Post

not sure what's up with the recommended answer...
I never marked this question solved :/

We recently started showing recommended answers even for questions not marked solved.

Jump to Post

let me do the work of translating it from python.

Will do. Maybe a better question would have been to omit Python but to flat out ask how to roll your own atan2() using sin, tan, etc

Nod to priors here and

Jump to Post

All 15 Replies

sorry for the late response, I wasn't notified :P
the reason I can't use atan2 is because the <eval> tag I'm working with at the bottom doesn't have the function.
I only requested python because it's easier to represent and read.

also, to elaborate on the problem, here's an actual conversion function:

def quaternion_to_euler(x, y, z, w):

    import math
    t0 = +2.0 * (w * x + y * z)
    t1 = +1.0 - 2.0 * (x * x + y * y)
    X = math.degrees(math.atan2(t0, t1))

    t2 = +2.0 * (w * y - z * x)
    t2 = +1.0 if t2 > +1.0 else t2
    t2 = -1.0 if t2 < -1.0 else t2
    Y = math.degrees(math.asin(t2))

    t3 = +2.0 * (w * z + x * y)
    t4 = +1.0 - 2.0 * (y * y + z * z)
    Z = math.degrees(math.atan2(t3, t4))

    return X, Y, Z

in this code, the issue is created here in handling the singularity:

    t2 = +1.0 if t2 > +1.0 else t2
    t2 = -1.0 if t2 < -1.0 else t2

I don't understand why it can't just do something like:

    t5 = +1.0 - 2.0 * (x * x + z * z)
    Y = math.degrees(math.atan2(t2, t5))

^ implemented practically, this would actually be t3, while the Z variables would be t4 and t5, but you get the point.

not sure what's up with the recommended answer...
I never marked this question solved :/

I would be guessing what this eval tag is. Maybe you are on some Python from years ago or something else. As it stands I can't see what's stopping you from using Python's math functions.

As to the mark solved, one wrong click and that happens.

not sure what's up with the recommended answer...
I never marked this question solved :/

We recently started showing recommended answers even for questions not marked solved.

commented: That's new. I missed it too. Right there "Recommended Answers" is the line above. +15
commented: I hope this isn't a way to auto-censor like YT does :/ +6

rproffitt, I think what Tcll is referring to is that we used to only show Recommended Answers for questions that have been marked solved. It was recently switched to additionally showing Recommended Answers for questions with a minimum number of replies that meet some additional quality criteria.

@rprofitt:

As to the mark solved, one wrong click and that happens.

trust me, I never clicked it, I'm really good with my mouse aside from MS Paint, as Dani explained, it's automated, which I can't say I agree with honestly :/
good ol YouTube buggy algorithm coming to DaniWeb x.x

@Dani: you can't fix this, comments are too unpredictable
if you really want to push forward with with a decent solution, self-recommendation would be a workaround.
but in that case I'd recommend a good reputation system so users with low reputation can't abuse the system to have troll remarks pushed forward.
(this is a double-edged sword with a way for malicious users to block notable users from making recommended answers)

but in all honesty, the old method is the best
it's an interesting idea, but please, don't fix what ain't broken ;)
yes I'm researching this myself (a logical way to restrict malicious abuse) for an old project of mine that'd shifted focus a bit.

but getting back on topic...
@rprofitt:

I would be guessing what this eval tag is. Maybe you are on some Python from years ago or something else. As it stands I can't see what's stopping you from using Python's math functions.

as stated in the OP, it's not python I'm working with
I'm only requesting python because it's easy for me to translate.

EDIT:
what I'm working with is a template for HexEdit 5 with a patched BinaryFileFormat.DTD (colors) from HexEdit Pro 4.0

or if you need an image, this is what I'm working with (different template):

^ looks like blocking the malicious gstatic domain disables this image for some reason...

Thanks for your updates. Sorry that I missed out on the DW changes but back on topic.

Can you tell us what language you are using? Maybe there is source code for atan2 in what you are coding in.

Can you tell us what language you are using? Maybe there is source code for atan2 in what you are coding in.

oof at the google link, but anyways...
as stated above HexEdit's template language is an XML varriant.

while it involves XML, it's actually somewhat C-like

I could work with it's <eval> tags to add atan2 functionality, but that'll only slow it down further, so I want to keep things as direct as possible...
I'm not sure how over the top this code is, but it's the first atan2() code I've found as of yet which seems to use atan().
why I'm complaining about speed is because the file I'm working with takes 20-30 seconds as is
(inevitably I'll be adding more time with the answer, but I'd like to keep it as minimal as possible)

is there another way I could do quat to euler without atan2??
(hopefully without branching logic if that can be done)

Going to need more from you Tcll. http://www.hexedit.com didn't work so I can't see what this language is.

As to oof, with all the source out there for atan2() is a variety of languages you are not lacking for examples. And without a language for me to take a look at I can't guess how I might code this up.

ah I see, alright, Andrew's site kinda died back in the day, and with it, his downloads...

I have the 2nd-most recent download of HexEdit 5 backed up on Mega here, as well as the BinaryFileFormat.DTD for color support (placed in the templates directory).
unfortunately I don't have the most recent anymore download (no thanks to Western Digital's shoddy HDDs) which fixed color support, added bitmap preview, and also improved eval parse performance.

there isn't much that covers the language but the included help file, but that only has limited info and doesn't cover <switch>, <case>, or BGR colors, nor does it cover most of the eval functions (use the calculator for this).

As to oof, with all the source out there for atan2() is a variety of languages you are not lacking for examples.

actually, the oof was just because Google is almost no different from me installing a RAT on your (and everyone else's) device(s) and selling everything you do to advertizers while awarding a portion of the revenue to volunteers to profit me even further.
or in other words, Google is illegal and very malicious (and of course, not alone)... I'm amazed at how everyone's perfectly fine with this.

I actually can't use google without a VPN because iptables somehow locked itself up (continues blocking without a rule) when I blocked them (not that I'm complaining, I'm actually thankful).
and even while I can use it through a VPN, I try to avoid it as much as physically possible.

I mainly use DDG despite being uncomfortable with it as of recent (which Yanoo raises these concerns as well, being just as bad)
so yeah, you can see why I'm having trouble finding a decent code :)

ok so I've literally just tested this against Blender results and it outputs roughly the same thing, though the model I'm working with only rotates along 1 axis per keyframe, so I don't really have anything decent to test against. x.x
take this with a bucket (or more) of salt as I'm not a mathematician: (literally me being a 12-yr old playing with clay)

from math import atan2, degrees
def quaternion_to_euler(x, y, z, w):
    return degrees(atan2(
        2.*(w*x+y*z),
        1-2.*(x*x+y*y)
    )), degrees(atan2(
        2.*(w*y-z*x),
        1-2.*(x*x+z*z)
    )), degrees(atan2(
        2.*(w*z+x*y),
        1-2.*(y*y+z*z)
    ))

I was mainly concerned with the Y axis, but it seems to work decently so far...
maybe rotating more than 1 axis will throw it off. :P

Ooof!

OK, try Duckduckgo.com then. I would be guessing you meant DDG === DuckDuckGo.com

Back on topic. Without some document on the language I'm stuck too. Over the years I've coded in a dozen plus HLLs (high level languages) and because of my work in embedded design and coding for same, assembler and C for over a dozen microcontrollers which has lead me to look at source code for missing functions as inspiration for the assembler and C at times.

All that background is not going to help here if there is no canonical standard (read https://www.webopedia.com/TERM/C/canonical.html ) or documentation I can take a gander at. If you write I have to install some dead system to read it's help file, for me it's the end of the line.

try Duckduckgo.com then.

I actually have been since about 3 weeks before asking (reasons more related to quat to euler with a little atan2 on the side) ;)
sure I could've just been doing the wrong searches and haven't been thinking of the right solution for about 3 days now since my brain decided to tire of so much stress (can still work on the side, but anything major, and I start not thinking straight), but that's why I decided to ask here.

If you write I have to install some dead system to read it's help file

yeah that's exactly why I've been so heasitant about it... let me do the work of translating it from python.
I just need a simpler function that relies on atan() if not some better method with sin()/cos()/tan() or functionless basic math pain or whatever...
I HAVE all those functions, I just don't have atan2() for some odd reason...

let me do the work of translating it from python.

Will do. Maybe a better question would have been to omit Python but to flat out ask how to roll your own atan2() using sin, tan, etc

Nod to priors here and https://www.researchgate.net/post/What_is_the_difference_between_arctan_and_arctan2_in_matlab_simulink

commented: I actually needed help with validating euler conversion as well, which is why that was the main focus. ;) +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.