ChristopherChudzicki / math3d-react

A user-friendly 3d graphing calculator for the web. Create, share, and animate 3d mathematical scenes.
https://www.math3d.org
Mozilla Public License 2.0
250 stars 34 forks source link

Inaccessible functions and related inconsistent behavior #241

Open NeatNit opened 4 years ago

NeatNit commented 4 years ago

I'm trying to experiment with a polar function but using X,Y coordinates. I can't seem to successfully convert from x,y to polar, because some MathJS functions are not accessible for some reason.

Here's some examples: https://www.math3d.org/AceRGTEq

The main approach is r = sqrt(x^2 + y^2) (which works, of course) and theta = atan2(y, x). Unfortunately, for some reason atan2 is not recognized as a function even though it is part of the mathjs library. It might be because of the 2 in the function name, but I doubt it.

The second approach for theta is to get the argument of the complex value x+iy. Complex numbers do work in Math3D, using the complex(x,y) constructor, but the attempt to use the arg function fails again - it is not recognized.

The third approach is the same as the second, but using the member function complex(x,y).arg() instead of the global (library) one. This function is actually undocumented but it does show up if you poke around in the console. When trying it in an Explicit Surface, it visually looks like there's arguments missing, but in practice the surface does render correctly. It works. image

However, despite working in explicit surfaces, it does not work in Variable or Function definitions, spitting out the error: "Eval Error: Depends on undefined symbol(s) arg". This makes it impossible to calculate partial derivatives and the like.

Unrelatedly, the function arccot also isn't recognized, while other inverse trigonometric functions (arcsin, arccos, arctan, etc) work.

To sum up

ChristopherChudzicki commented 4 years ago

Thanks for posting this! I am on vacation now but will look at it more closely when I get back later next week.

Re atan2 in particular I believe (but cannot remember for sure) that the arctan(...) function in math3d is variadic and can take 1 or 2 arguments. I believe the two variable order is arctan(y,x).

BTW: math3d uses a somewhat old version of math JS and a custom build. If you’re curious about the details the math object is global and can be inspected in console. I really should update the version…

Wrote this on my phone… Hope there’s not too many typos.