X16TRIG A graphical demo of circle and angles (R48)

Post Reply
Xiphod
Posts: 600
Joined: Thu Apr 15, 2021 8:05 am

X16TRIG A graphical demo of circle and angles (R48)

Post by Xiphod »

Had some time during a plane trip, so decided to do a simple program to demonstrate calculating rotation angles.

This uses the CBM BASIC built in trig. function COS, SIN, ATN to maintain the rotation angle of two lines (a "reference line" and a "mouse line"), as well as the angle between these two lines.

Like most trig function implementations, you may need to "fiddle around" to determine the sign convention or range convention (i.e. to scale -180 to +180 or 0 to 360), and whether you want to work in radians or degrees. In modern era there is ATAN2 function (C std lib and even in Excel) to help resolve many of the quadrant-issues with ATN.

Maybe this might help with some sprite rotation concepts (tho a sprite library might use different conventions; for CBM BASIC, 0degrees ended up to the right and positive is clockwise, and I chose to scale everything to -180 to +180). But just a fun little BASLOAD reference example. This could be useful for producing look-up-tables for other fancier programs (find the range and resolution of interest and export the computed values to a file).

System ROM R48 required (for call to RING, which could be removed from the program - the RING just gives a visual guide to the radius), and MOUSE required for full usage (could be easy enough to change that to JOY calls instead). The reference-line is manipulated via the keyboard.

EDIT: Updated now to show the triangles of the two reference lines.

EDIT: Online X16 emulator has been updated to R48, so TryItNow here works for this
Try It Now!

x16trig.jpg
x16trig.jpg (184.59 KiB) Viewed 9637 times
Attachments
X16TRIG.ZIP
(161.21 KiB) Downloaded 186 times
X16TRIG.PRG
(2.16 KiB) Downloaded 187 times
X16TRIG.BASL.TXT
(5.67 KiB) Downloaded 131 times
Post Reply