I’m using a basic atom bot board and basic atom 28
I got the formula to plot a circle
a and b are the center of circle
r is the radius
and t is suppose to be the degree in rads
here is my code
x = cos cnt * rn1(0) + a
y = sin cnt * rn1(0) + b
cnt is my degree
rn1(0) is my radius from my ultra sonic range finder (6-255)
I know this works i have used it before just not in basic atom
Are you trying to let people know of a method of drawing a circle? Or are you having trouble with it?
I haven’t used a BS in a while so I’m not sure what the syntax is supposed to be in MBasic… Shouldn’t it be something like this:
x = (cos(cnt) * rn1(0)) + a
y = (sin(cnt) * rn1(0)) + a
Also, is cnt in degrees or radians? It is supposed to be in radians according to the manual, but I find that weird because all other trig functions use radians by default.
Also, how large is your LCD? If your radius is from 6-255, then you need a minimum of a 255 x 255 LCD (More likely a 256 x 256).
Also, what is your center? If it is a 255 LCD, then you need the center to be 127.
yes cnt is suppose to be radians, I guess the real question is how would i convert degrees to radians.
all radius will be divided by 10 so it should fix in the lcd 160x80
The real reason for this circle is to try and use distance points to figure were i have moved to so some points will be off the screen.
So simply divide cnt by .0174 (4 significant digits is enough) and you then have your radians.
After you divide the radius by 10, make sure to EITHER ceil or floor it. Do not round it to the nearest digit because your circle will be a bit off and wont be perfect. I would suggest to use round since you will have plenty of space. Make the circle nice, big, and visible.
depending on the precision of the floating point support, and if it has the constant pi defined, you might get better accuracy using degrees * pi / 180 rather than just hard coding the 0.01745 constant yourself.
Cos and Sin are integer based commands not floating point based. They are in the same format as the commands in PBasic. Values are signed 8bit(eg -0x80 to 0x7F). To get a floating point value you would take the return value from sin or cos and divide by 128 and multiply by PI(eg ((sin(angle)/128)*3.14)=radians). Also the argument for sin and cos is in binary degrees(eg 0 to 255 = 0 to 360 degrees).
P.S. there are floating point version of sin and cos in AtomPro basic(eg FSIN and FCOS) along with other floating point trig functions. Atom and MBasic for PIC do not have the floating point trig functions.
you do realize that plotting ines and circles on graphics displays by actually using sin and cos functions is more than a little overkill, yes? here is a start on line drawing and there is also an explaination on drawing circles as well.
(could not get the link to work correctly as the parser seems to have a problem with the apostrophe in the name. you’ll have to block copy and paste it to make it work, or just search for breesenham)