How do I make a function to draw arcs inside a mat

2019-09-25 03:44发布

问题:

I need to make a function/method that draws arcs inside a matrix. I would use 1s as points that shape the arc and 0s as empty spots. So the function would produce something like this matrix (only I would use 1400x700 matrix in reality):

000000000000000
000100000001000
000010000010000
000000111000000
000000000000000

I need to pass the following parameters to the function:

x: the x coordinate

y: the y coordinate

w: the width

h: the height

start: the start angle, in degrees

extent: the extent, in degrees

Now, I don't know the math on how to do it. Anyone could help me?

回答1:

Hint:

A circular arc is the boundary of a domain of equation

(X - Xc)² + (Y - Yc)² ≤ R².

A starting point can be

(Xc + R, Yc).

Now from a known point, you can perform contour following, i.e. repeatedly find the next 8-neighbor that verifies the inequation.

This gives you a global idea. Handling the start and end point is a little tricky. And optimizations are possible by splitting the work in 8 octants. But this is a longer story.