On April 4th, I posted software that drew circles on a GLCD. In the software, I used the equation for a circle- x^2 + y^2 = Radius^2. In the first version I solved this equation for Y which produced a top and bottom half of a circle but left open areas along the left and right sides of the circle.
To fill in these areas I modified the software to solve for X. This produced a left half and a right half of a circle with openings at the top and bottom.
By combining these two solutions I filled in the circle openings. The new portion is the second FOR.... NEXT loop.
My GLCD is very noisy and prone to generating spurious pixels but I think this fix solves the problem. If anybody tries this please let me know what you find.
Here is the software.
;Variables
Dim Radius, Radius_2 As integer
Dim x_1, x_2, x_3, y_1, y_2, y_3, z_1, G_1 As integer
'
InitGLCD
GLCDCLS
'
'RADIUS is the radius of the circle - Must be <= 31 for 128x64 display
'OffsetX is the left most edge of the circle
'OffsetY is the top most edge of the circle
'
'Some examples using the CIRCLE command
'
Circle 16, 48, 15; Small circle with center in MIDDLE of display
Circle 10, 10, 10; Circle in TOP LEFT of display
Circle 10, 100, 10; Circle in TOP Right of display
Circle 10, 10, 40; Circle in BOTTOM LEFT of display
Circle 10, 100, 40; Circle in BOTTOM Right of display
Circle 32, 32, 0; Large circle with center in MIDDLE of display
'
'SUB ROUTINES ********************************************
'
Sub Circle (In Radius, In OffsetX, In OffsetY)
'For a 128x64 GLCD -
' Radius cannot exceed 63/2 = 31
' If 2xRadius plus OffsetX > 127, circle will move off right edge of screen
' If 2xRadius plus OffsetY > 63, circle will move off bottom edge of screen
' The below two IF statements address this situation by reducing OffsetX and/or OffsetY
If (2 * Radius + OffsetX) > 127 then
OffsetX = 127 - (2 * Radius)
end If
'
If (2 * Radius + OffsetY) > 63 then
OffsetY = 63 - (2 * Radius)
end If
'
Radius_2= Radius * (-1); Negative Radius numbers for plotting other side of circle
'***********************************************************************
'Solve for y - this portions leaves openings on the SIDES the of the circle
' Combining with second FOR..NEXT section fills in the openings
'
For x_1 = Radius_2 to Radius
y_1 = (Radius * Radius) - (x_1 * x_1); x-axis squared
'
Sq_Root y_1, G_1
'
x_2 = x_1 + Radius + OffSetX; x-axis
y_2 = G_1 + Radius + OffSetY; y-axis for bottom half of circle
y_3 = abs(G_1 - Radius) + OffSetY; y-axis for top half of circle
'
pset x_2,y_2,on; Bottom half of circle
pset x_2,y_3,on; Top half of circle
'
next
'********************************************************************
'Solve for x - this portions leaves openings on the TOP and BOTTOM of the circle
' Combining with first FOR..NEXT section fills in the openings
'
For z_1 = Radius_2 to Radius
x_1 = (Radius * Radius) - (z_1 * z_1); y-axis squared
'
Sq_Root x_1, G_1
'
y_2 = z_1 + Radius + OffSetY; y-axis
x_2 = abs(G_1 - Radius) + OffSetX; x-axis for left half of circle
x_3 = G_1 + Radius + OffSetX; x-axis for right half of circle
'
pset x_2,y_2,on; Left half of circle
pset x_3,y_2,on; Right half of circle
'
next
'********************************************************************
'
End Sub
Sub Sq_root (In y_1, G_1)
'SQUARE ROOT Approximation &&&&&&&&&&&&&
'
G_1 = 200;First Guess for 5 Digit y_1
If y_1 < 10000 then
G_1 = 60;First Guess for 4 Digit y_1
End If
If y_1 < 1000 then
G_1 = 20;First Guess for 3 Digit y_1
End If
If y_1 < 100 then
G_1 = 6;First Guess for 2 Digit y_1
End If
If y_1 < 10 then
G_1 = 2;First Guess for 1 Digit y_1
End If
'
G_1 = (G_1 + (y_1 / G_1))/2
G_1 = (G_1 + (y_1 / G_1))/2
G_1 = (G_1 + (y_1 / G_1))/2
G_1 = (G_1 + (y_1 / G_1))/2;Square Root of y_1
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Attached a pic of the results from MBB's rev1 circle code. Definitely closed about the x axis now, but have a new set of problems to contend with. It would appear that several locations, in any particular quadrant, the algorithm cannot decide whether a pixel is to be inside, or outside, the circle radius. The smaller centered circle does appear very close.
Please don't take this as criticism, but only an observation. Keep up the good work :).
Thanks for trying this. What model display are you using. My display showed more closure on the circles than yours did.
I also noticed that the pixels appeared inside , on or outside the circle radius but I wasn't sure because my GLCD is very noisy and prone to producing spurious pixels. You confirmed its the algorithm unless your using the same display I am. I'm using a Hantronix HDM64GS12L-N31S display.
This algorithm problem could be in part due to the integer math in the software and the pixels being integer values
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Have you instituted the fix for the Pset bug? If you Set GLCD_CS1, and GLCD_CS2 Off after GLCDCS then you should get rid of the random pixel(s).
The separation, or offset, in some quadrants seem to be related to the radius? Haven't actually tried to count the pixels. So, if you don't have the circle offset's seen in the previous post's pic, then maybe there is a code cut and paste error?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MBB, I want to apologize to you as I did with Thomas Henry, I have had a hookup problem with the GLCD, with a couple of switched data lines. So previous posted picture is bogus, not your fault.
Corrected pic:
P.S. I've got some missing pixels on the right due to a toasted controller pin :).
On April 4th, I posted software that drew circles on a GLCD. In the software, I used the equation for a circle- x^2 + y^2 = Radius^2. In the first version I solved this equation for Y which produced a top and bottom half of a circle but left open areas along the left and right sides of the circle.
To fill in these areas I modified the software to solve for X. This produced a left half and a right half of a circle with openings at the top and bottom.
By combining these two solutions I filled in the circle openings. The new portion is the second FOR.... NEXT loop.
My GLCD is very noisy and prone to generating spurious pixels but I think this fix solves the problem. If anybody tries this please let me know what you find.
Here is the software.
Let me finish the new GLCD driver I am writing and I can give this a go. Thank you.
Attached a pic of the results from MBB's rev1 circle code. Definitely closed about the x axis now, but have a new set of problems to contend with. It would appear that several locations, in any particular quadrant, the algorithm cannot decide whether a pixel is to be inside, or outside, the circle radius. The smaller centered circle does appear very close.
Please don't take this as criticism, but only an observation. Keep up the good work :).
Kent,
Thanks for trying this. What model display are you using. My display showed more closure on the circles than yours did.
I also noticed that the pixels appeared inside , on or outside the circle radius but I wasn't sure because my GLCD is very noisy and prone to producing spurious pixels. You confirmed its the algorithm unless your using the same display I am. I'm using a Hantronix HDM64GS12L-N31S display.
This algorithm problem could be in part due to the integer math in the software and the pixels being integer values
My GLCD unit is from AZ Displays AGM1264F.
Have you instituted the fix for the Pset bug? If you Set GLCD_CS1, and GLCD_CS2 Off after GLCDCS then you should get rid of the random pixel(s).
The separation, or offset, in some quadrants seem to be related to the radius? Haven't actually tried to count the pixels. So, if you don't have the circle offset's seen in the previous post's pic, then maybe there is a code cut and paste error?
MBB, I want to apologize to you as I did with Thomas Henry, I have had a hookup problem with the GLCD, with a couple of switched data lines. So previous posted picture is bogus, not your fault.
Corrected pic:
P.S. I've got some missing pixels on the right due to a toasted controller pin :).
Last edit: kent_twt4 2014-04-18