Polar-Rectangular Conversion

Authors

Publication

Pub Details

Date

Pages

See all articles from SyncWare News v1

This program converts between polar notation (magnitude and angle) and rectangular (or “Cartesian”) notation (“X” and “Y” values) of vector quantities and complex numbers. Many scientific calculators have this function, which often proves useful if you deal with vectors or phasors. On the ZX81, this can be accomplished quite easily using the SIN, COS, ArcTaN, and SQR functions, The program will fit into un-expanded ZX81/TS1000s.

PLR-CART goes a step beyond most calculators in allowing negative values for the magnitude in polar expressions. For example, “R=-5, A=30 deg.” and “R=5, A=210 deg.” are both mathematically correct, and indicate the same vector, but calculators generally don’t accept expressions like the first, whereas this program will. Going the other way, from Cartesian to Polar, always gives a positive magnitude (generally considered preferable). The ZX81 trig functions automatically handle negative angles and angles greater than 2*PI radians (360 deg.), so we don’t need to bother with this in the program.

To use the program, enter RUN with the machine in SLOW mode. You’ll be prompted which way you want to convert, and then be asked to INPUT the appropriate variables. Going from Polar to Rectangular (Cartesian) you have the option of expressing the angle in degrees or radians. Pressing any key except BREAK after the answer appears gets you back to the beginning of the program.

The expression NOT PI is used throughout the program instead of zero to conserve memory space. (It takes six extra bytes to store the binary representation of a number in the program area.) Try it yourself – enter PRINT NOT PI. Review the manual section on logical operators if you’re not sure why this works,

5 CLS
10 SLOW
20 PRINT "PLR-> CART ""C""",,"CART-> PLR ""P"""
30 LET A$=INKEY$
70 GOTO 170*(A$="C")+270*(A$="P")+30
200 CLS
205 PRINT "DEG ""D""",,"RAD ""R"""
210 LET A$=INKEY$
220 LET K=(A$="R")+(A$="D")*PI/180
230 IF NOT K THEN GOTO 210
240 CLS
250 PRINT "R=";
255 INPUT R
260 PRINT R,"A=";
270 INPUT A
280 PRINT A;" ";A$,,,
285 LET X=R*COS (K*A)
287 LET Y=R*SIN (K*A)
290 PRINT "X=";X,"Y=";Y
295 IF INKEY$="" THEN GOTO 295
297 GOTO NOT PI
300 CLS
310 PRINT "X=";
320 INPUT X
330 PRINT X,"Y=";
340 INPUT Y
350 PRINT Y,,,
360 LET R=SQR(X*X+Y*Y)
370 LET A=ATN(Y/X)
380 IF X<NOT PI THEN LET A=A+PI
390 PRINT "R=";R,"A=";A," R",,"=";A*180/PI;" D"
400 GOTO 295
410 CLEAR
420 SAVE "PLR-CART"
430 RUN

Products

 

Downloadable Media

 
Scroll to Top