Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rectangular/Polar coordinate converter using Inform-PE
#1
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?


Attached Files
.bas   R2P.bas (Size: 12.26 KB / Downloads: 35)
.bas   R2P-InForm form.bas (Size: 5.39 KB / Downloads: 28)
It's not the having, it's the doing.
Reply
#2
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.


Attached Files
.zip   R2P.zip (Size: 202.28 KB / Downloads: 14)
Reply
#3
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
b = b + ...
Reply
#4
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
b = b + ...
Reply
#5
From the slider, aren't you getting angle in Radians and not Degree?  See images above.
Reply
#6
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.
b = b + ...
Reply
#7
(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
Reply
#8
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.
b = b + ...
Reply
#9
Pfft, 2 minutes.  Tongue

Can you image what we need to go through to debug something in the QB64 compiler?  Big Grin
Reply
#10
(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
Reply




Users browsing this thread: 1 Guest(s)