I am wondering if anyone here can help me with some pseudocode or at least point me in the right direction on how to draw a circle segment without anti-aliasing.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The formula for points on a circle are:
where
xcenterandycenterare the center of the circle,radiusis the radius andthetais the angle.You simply have to iterate
thetafrom your starting angle to your ending angle in small enough steps, and extract thexandyvalues for plotting, and keep in mind that most trigonometric functions take their arguments as radians (0 through 2*PI) rather than degrees (0 through 360) – adjust your start and end angles and yourthetastep to take this into account.Pseudo-code would be something like the following:
although you’d probably want to normalise the angles to be between 0 and 2*PI, and then swap the start and end angles if the former is greater than the latter.
If you want more efficient code, you can look into the midpoint circle algorithm. The math is heavier and it’s slightly complicated by the requirement that you only want a segment (meaning you’ll need to know the angle, something not usually necessary for this algorithm with a full circle) but that might be a good starting point if the simplistic algorithm above is not fast enough.