Calculating radials of a shape

83 views Asked by At

I'm traing to identify road-sign shapes using radials. I have the center point of the shape and I must find 7 radials to identify the figure. To find 7 radials I must find points at 0º, 30º, 60º and 90º, like in the following image (image a):

https://lh4.googleusercontent.com/-sFsGXGD9VGI/TqxRjwIoSPI/AAAAAAAAAD0/yUOhN7RNUhU/s445/radiais.png

The problem is, I don't know how to find a point that is on 30º from my center.

Look, on my first implamentation I was calculating 5 radials (0º, 45º and 90º), like image b: To find the points at 0º I did:

//fix the y coordinate and increment x coord
for(x = center.x to width)
    pixel(x, center.y)

To find the points at 90º I did:

//fix the x coordinate and increment y coord
for(y = center.y to height)
    pixel(center.x, y)

To find the points at 45º I did:

//increment x and y coord in the same number
for(x = center.x, y = center.y to width, height)
    pixel(x, y)

So, I want to know how to access points at 30º and 60º.

ps.: sorry, a cannot post images yet! no reputation.

1

There are 1 answers

0
BlackBear On BEST ANSWER

You can use the polar coordinate system. Here's a pseudocode:

theta = 30 * pi / 180                      // 30, 60, whatever
for r = 0 to length_of_line
    x = center.x + r * cos(theta)
    y = center.y + r * sin(theta)
    pixel(x, y)

This way you can draw radials with inclination of 12, 16, 94.7362, ... degree