X16TRIG A graphical demo of circle and angles (R48)

Post Reply
voidstar
Posts: 496
Joined: Thu Apr 15, 2021 8:05 am

X16TRIG A graphical demo of circle and angles (R48)

Post by voidstar »

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.

NOTE: TryItNow won't work until online emulator updated to R48.
Try It Now!

x16trig.jpg
x16trig.jpg (184.59 KiB) Viewed 340 times
Attachments
X16TRIG.ZIP
(161.21 KiB) Downloaded 41 times
X16TRIG.PRG
(2.16 KiB) Downloaded 38 times
X16TRIG.BASL.TXT
(5.67 KiB) Downloaded 42 times
Post Reply