QB64 Phoenix Edition
Rectangular/Polar coordinate converter using Inform-PE - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8)
+---- Thread: Rectangular/Polar coordinate converter using Inform-PE (/showthread.php?tid=3000)

Pages: 1 2


Rectangular/Polar coordinate converter using Inform-PE - bobalooie - 09-03-2024

Hello all,

I decided to experiment a bit with the Inform-PE system, so I resurrected a program I first wrote for a RS TRS-80 Model 4 with a hi-res graphics board. It is a small utility that converts rectangular 2D coordinates to polar and vice versa. The program also presents a simple 2D graphical view of the conversion result.

Comments and suggestions are welcomed.

Note to admins: I had to rename the R2P-Inform.frm file because the webpage wouldn't allow me to attach a .frm file. Is that something that can be fixed?


RE: Rectangular/Polar coordinate converter using Inform-PE - a740g - 09-05-2024

Very nice.

Had to make some tiny changes to make it work on macOS.

Sharing my changes here with the latest version of InForm-PE runtime included.


RE: Rectangular/Polar coordinate converter using Inform-PE - bplus - 09-05-2024

zip thats what this needs! thankyou!

BTW I think it would much more useful to have a R2P function and an P2R function. But how do you return two values? I guess you make it a sub and change the inputs to outputs, ie x, y in and angle, distance out for R2P and the reverse for P2R.

Like this:
Code: (Select All)
x = 10: y = 10
R2P x, y
Print x, y

P2R x, y
Print x, y

Sub R2P (XinAngleoutDegrees, YinDistanceOut)
    x = XinAngleoutDegrees
    y = YinDistanceOut
    XinAngleoutDegrees = _R2D(_Atan2(y, x))
    YinDistanceOut = Sqr(x * x + y * y)
End Sub

Sub P2R (AngleInDegreesXout, DistanceInYout)
    a = _D2R(AngleInDegreesXout)
    AngleInDegreesXout = DistanceInYout * Cos(a)
    DistanceInYout = DistanceInYout * Sin(a)
End Sub



RE: Rectangular/Polar coordinate converter using Inform-PE - bplus - 09-05-2024

OK tested InForm version
R2P
   
looks good!

P2R
   
eeeh! 45 degrees means x must equal y

2 mins to compile InForm and it's wrong. Sad


RE: Rectangular/Polar coordinate converter using Inform-PE - SMcNeill - 09-07-2024

From the slider, aren't you getting angle in Radians and not Degree?  See images above.


RE: Rectangular/Polar coordinate converter using Inform-PE - bplus - 09-07-2024

OK that might be it, I had it set on Degrees to do the first calc. It must of jumped back. That is unexpected behavior.


RE: Rectangular/Polar coordinate converter using Inform-PE - SMcNeill - 09-07-2024

(09-07-2024, 01:01 PM)bplus Wrote: OK that might be it, I had it set on Degrees to do the first calc. It must of jumped back. That is unexpected behavior.

That's only because you weren't expecting it to reset.  Now you know it will, so it's the expected result.  Big Grin Wink


RE: Rectangular/Polar coordinate converter using Inform-PE - bplus - 09-07-2024

Well I said what I wanted to say, and I gave those 2 subs for handy tools to get those conversions without all the rig-a-ma-roll of an InForm app and still not have a couple of simple subs to take away from it.

Good practice with InForm, must of taken hours to assemble. I can't image waiting 2 minutes for every compile to get the thing up and running. Great effort there! I am sure Stax would appreciate the mathematically correct, anti-Basic way of graphing with Y axis increasing going up.


RE: Rectangular/Polar coordinate converter using Inform-PE - a740g - 09-07-2024

Pfft, 2 minutes.  Tongue

Can you image what we need to go through to debug something in the QB64 compiler?  Big Grin


RE: Rectangular/Polar coordinate converter using Inform-PE - SMcNeill - 09-07-2024

(09-07-2024, 06:04 PM)a740g Wrote: Pfft, 2 minutes.  Tongue

Can you image what we need to go through to debug something in the QB64 compiler?  Big Grin

A really dang good PC and not one twenty years old!!  Big Grin