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.
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- Space complexity of validation of a binary search
相关文章
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- Difference between SuspendLayout and BeginUpdate
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
For integer-only circle-drawing, see wikipedia's midpoint circle algorithm article. It presents, with code, a sort of circle-variant of Bresenham's line algorithm. See codecircle for comparisons (with codes) of midpoint circle algorithm, Bresenham's circle algorithm, and an optimized third method.
The formula for points on a circle are:
where
xcenter
andycenter
are the center of the circle,radius
is the radius andtheta
is the angle.You simply have to iterate
theta
from your starting angle to your ending angle in small enough steps, and extract thex
andy
values 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 yourtheta
step 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.