Shop OBEX P1 Docs P2 Docs Learn Events
Plotting points on a circle — Parallax Forums

Plotting points on a circle

NewzedNewzed Posts: 2,503
edited 2005-12-12 07:32 in General Discussion

Here is a neat little program. It only took about four hours to write but it took me four days to figure out how to write it.

Anyway, the program plots 3, 4, 5, 6 and 15 points in each quadrant of a circle. This is equivalent to 12, 16, 20, 24 or 60 points on a circle.

The 15 point routine is specifically for a clock, and by default prints coordinates for a 4-inch diamter circle. I laid it out in ExpressPCB using T1-3/4 LEDs for the hour points and T1 LEDs for the minute points.

Instructions In Program Notes at the beginning of the program tell you how to program for different radius circles. When you load the program it will ask for the number of points per quad. Key in
the number, then press Enter. The program will prompt you to press any key to start.

This program is written for a BS2E but will work on any Stamp from a BS2 on up. It might even work on a BS1 –didn’t try it so I don’t know.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

Comments

  • Tracy AllenTracy Allen Posts: 6,666
    edited 2005-12-11 18:42
    Hi Sid,

    I'm curious, why did you use LOOKUPs instead of the SIN and COS operators?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NewzedNewzed Posts: 2,503
    edited 2005-12-11 18:58
    I tried the sin operator from the Help file using:

    sine = SIN (degr * 128 / 180)················
    DEBUG "Angle: ", DEC degr, TAB
    DEBUG "Sine:· ", SDEC sine, CR

    but when I plotted them, the coordinates were not very close.· That's when I decided to use the lookup tables.· As far as I could tell, the coordinates were perfect when using LOOKUP.

    Is there a better way to do it?

    Sid
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2005-12-12 07:32
    Not close how? The sine & cosine values in Stampese go from -128 to +128, so they need to be rescaled to get standard -100 to +100 (representing -1.00 to +1.00). Granted, your table lookup is more precise, because it is storing 3 significant figures.

    FOR degs=0 TO 360 STEP 6 
      brads = degs */ 182  ' brads from 0 to 256
      sine = SIN brads
      cosine = COS brads
      IF sine.bit15=1 THEN sine = - (ABS sine */200) ELSE sine = sine */ 200  ' rescale
      IF cosine.bit15=1 THEN cosine = -(ABS cosine */200) ELSE cosine = cosine */ 200
      DEBUG CR, DEC degs, TAB, SDEC sine, TAB, SDEC cosine
    NEXT
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.