Tim Wesserman or Edward Shore
03-15-2019, 10:44 PM (This post was last modified: 03-16-2019 12:15 PM by mathnovice.)
Post: #1
 mathnovice Junior Member Posts: 7 Joined: Jun 2018
Tim Wesserman or Edward Shore
I do ask this of 2 great minds? Here is the deal, I need to extend the function atan2(y,x). It is in FORTRAN and I have no idea about that. Attached is a function that with computational ease keeps track of coordinates on a sphere much faster than current computational times.

It is because of you 2 that I understood the programming language of HP Prime to define some functions. These functions were part of ancient trigonometry that is well studied and well behaved. It is a bit computationally heavy for humans, but if we allowed for billions of iterations a second, the best choice of methods is this for sure. Versin(x), EXESEC(x), and so on.....

The F is for Folium of Descartes. If I had never read you 2 I could have never answered the question "What is the derivative of CVCSIN(x)", why, "Because I want to know".

03-15-2019, 11:09 PM
Post: #2
 chromos Member Posts: 208 Joined: Jun 2015
RE: Tim Wesserman or Edward Shore
It's a pity that with your title you have excluded a lot of other very smart people visiting this forum. But if you just want answer from two people you mentioned, maybe private message is better suited?

Geocaching Coords Solver, Number of triangles Puzzle
03-16-2019, 02:20 AM
Post: #3
 Thomas Klemm Senior Member Posts: 1,852 Joined: Dec 2013
RE: Tim Wesserman or Edward Shore
(03-15-2019 10:44 PM)mathnovice Wrote:  I need to extend the function atan2(y,x).

Not sure if this helps, but you can emulate atan2:

$$atan2(y, x) = 2 \arctan \frac{y}{r+x}$$ where $$r=\sqrt{x^2+y^2}$$

In Python:
Code:
from math import pi, sqrt, atan def atan2(y, x):     r = sqrt(x*x + y*y)     return 0.0 if r == 0.0 else pi if r + x == 0.0 else 2 * atan(y / (r + x))

Code:
>>> atan2(0, 0) 0.0 >>> atan2(0, 3) 0.0 >>> atan2(0, -3) 3.141592653589793 >>> atan2(2, 3) 0.5880026035475675 >>> atan2(-2, 3) -0.5880026035475675 >>> atan2(2, -3) 2.5535900500422257 >>> atan2(-2, -3) -2.5535900500422257

Quote:It is in FORTRAN and I have no idea about that.

Me neither.

Cheers
Thomas
03-16-2019, 08:59 AM
Post: #4 ijabbott Senior Member Posts: 1,261 Joined: Jul 2015
RE: Tim Wesserman or Edward Shore
Check out the polar_coordinates function in the HP Prime's function catalog.

— Ian Abbott
03-16-2019, 01:49 PM
Post: #5 JMB Member Posts: 98 Joined: Jan 2016
RE: Tim Wesserman or Edward Shore
You can also try ARG(X+Y*i)

Josep Mollera. HP PRIME, HW: C, SW: 2.1.14730 (2023 04 13).
03-16-2019, 03:39 PM
Post: #6
 mathnovice Junior Member Posts: 7 Joined: Jun 2018
RE: Tim Wesserman or Edward Shore
Yes maybe a general question or PM would have been better but it is because I wanted the correct answer on the first try, the first time. I am sure any person that enjoys problem solving can appreciate knowing there is no need to check this man's work.

The End Goal: I want to create a function that can easily define the intersection of 2 Geodesics in a Non-Commutative Polar form and in terms of the radius of the Sphere it occupies.

Yes this does seem very similar to Spherical Coordinates system (SC). There are many differences and once I explain a few maybe it becomes clear. SC at the start sounds like traditional polar, "There is a base Unit R and it begins at the pole, as R sweeps out a circle the distance of 1 endpoint of R is of an exact ratio, this ratio is theta then, s=r(theta). It is very hard to disagree with this logic. Now we have many ways to measure [x=rcos(theta) y=rsin(theta)], [r=sqrt(x^2+y^2], on and on...this in not a post on Pre calculus topics.

This next step in SC is what I am changing with this function. To take an additional measurement in SC we will define a new pole, which by choice also happens to be the Z-axis in Cartesian. I have no doubt about the amount of human thought when in to defining step in SC. I am speculating that the main motivation for this was: it was also super convenient and lucky that a measurement taken greater that pi/2 would return negative Cosine values, which has also placed them in the negative Z. Big picture: we defined which poles are which [X,Y,Z]-axis with purpose, and that was to align it with Cartesian, but the biggest reason is now SC stays on a commutative ring. (a field where a*b=b*a) also look close at how highly restricted SC is.

I have defined a Coordinate system that is recursive based and returns very simple values, but it does this at the expense of many many many small tedious calculations. If I did not have a computer I would never dream of doing math like this.

The hardest part of explaining is over. Now, start in Polar, with the same "R" and same "theta" that pops to mind, now, take your measurement. It does not matter if it [R,theta], [1,pi/7], or [4^89x,13pi/4]. The only rule here is to take ALL of your "theta" measurement. Now where your new "R" is in "theta" space IS (exactly is) your new pole as a base for an additional rotational measurement called (F). Now that R is the segment that defines the pole in our new rotation (F). So we now rotate some amount of units in a counter-clockwise fashion and assign its value to Z.
The identity that connects these is:

[R*cos(F)+R*Versin(F)=sqrt(x^2+y^2)=(R,theta)]

All those words to say what I really want in this program is it to ask me 3 questions, What is your (R), what is your (theta), what is your (F) ........computer does computations.....here ya go (X,Y,Z) Here is my (X,Y,Z).......Here is your (R,theta,F)

TLDR: Create a program that give me Poincare Sphere coordinates on an HP Prime because they are the greatest calculator in the world that what I do all my work on.

I have no doubt there are typos
03-16-2019, 06:25 PM
Post: #7
 SammysHP Member Posts: 165 Joined: Jul 2018
RE: Tim Wesserman or Edward Shore
I haven't really understood what you mean, but somehow quaternions come to my mind.
03-16-2019, 09:11 PM (This post was last modified: 03-16-2019 09:25 PM by Albert Chan.)
Post: #8
 Albert Chan Senior Member Posts: 2,230 Joined: Jul 2018
RE: Tim Wesserman or Edward Shore
I was curious what should be result of atan2(±0.0, ±0.0)

Below code based on Charles Petzold's blog: Atan2 and Exceptions (and why there aren't any)

Code:
from math import atan, pi, copysign def my_atan2(y, x):     if x>0: return atan(y/x)      if x<0: return atan(y/x) + copysign(pi, y)     if y: return copysign(pi/2, y)     if copysign(1,x) < 0: x = pi     return copysign(x, y)

z = 0.0
my_atan2(z,z) --> 0.0
my_atan2(-z,z) --> -0.0
my_atan2(z,-z) --> 3.14159
my_atan2(-z,-z) --> -3.14159
03-17-2019, 02:59 AM (This post was last modified: 03-17-2019 03:08 AM by toml_12953.)
Post: #9
 toml_12953 Senior Member Posts: 2,031 Joined: Dec 2013
RE: Tim Wesserman or Edward Shore
(03-16-2019 02:20 AM)Thomas Klemm Wrote:
(03-15-2019 10:44 PM)mathnovice Wrote:  I need to extend the function atan2(y,x).

Not sure if this helps, but you can emulate atan2:

$$atan2(y, x) = 2 \arctan \frac{y}{r+x}$$ where $$r=\sqrt{x^2+y^2}$$

In Python:
Code:
from math import pi, sqrt, atan def atan2(y, x):     r = sqrt(x*x + y*y)     return 0.0 if r == 0.0 else pi if r + x == 0.0 else 2 * atan(y / (r + x))

Code:
>>> atan2(0, 0) 0.0 >>> atan2(0, 3) 0.0 >>> atan2(0, -3) 3.141592653589793 >>> atan2(2, 3) 0.5880026035475675 >>> atan2(-2, 3) -0.5880026035475675 >>> atan2(2, -3) 2.5535900500422257 >>> atan2(-2, -3) -2.5535900500422257

Quote:It is in FORTRAN and I have no idea about that.

Me neither.

Cheers
Thomas

I get the same answers with ARG(Y+X) without having to write a function.

Code:
>>> ARG(0+0i) 0.0 >>> ARG(3+0i) 0.0 >>> ARG(-3+0i) 3.141592653589793 >>> ARG(3+2i) 0.5880026035475675 >>> ARG(3-2i) -0.5880026035475675 >>> ARG(-3+2i) 2.5535900500422257 >>> ARG(-3-2i) -2.5535900500422257

Tom L
Cui bono?
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)