views:

175

answers:

4

So I've been messing around with http://processingjs.org/.

I want to draw a circle that has a bunch of lines protruding from it. Each of these lines should perpendicular to the tangent of the circle.

I don't necessarily need to know how to do this in processing.js, but I don't really remember my trigonometry, so more of an explanation of the math required to draw this line would be helpful, but if you know how to do it in processing.js, that would be cool too.

Thanks.

+2  A: 

If the line is perpendicular to a tangent to the circle, it would pass through the center of the circle if extended. If your circle is centered at (a,b) with radius r, and you want it to come out at angle t, then the start points are x1=a+r*cos t, y1=b+r*sin t (I've assumed you want the line to start at the circumference, which is what your question seems to imply) and if you want the line to be of length z, your end points are x2=x1+z*cos t, y2=y1+z*sin t and you can use the processing command

line(x1,y1,x2,y2)

Edit: Note that my t is measured clockwise from the x-axis. If you want it to be counter-clockwise (which is normal in maths) you can replace sin t with -sin t in both places above, since processing has increasing y going down.

Ramashalanka
This is awesome thanks. Just to verify, t would be the angle from the circumference the line would protrude?
icco
No problem. In answer to your comment: no. The angle from the circumference is always a right angle (as you requested). The angle t is the angle the line makes with the x-axis. So if you want it going straight down you'd use pi/2 (i.e. 90 degrees: processing uses radians), as originally written (with t being clockwise).
Ramashalanka
Sorry, I misworded my comment, I implemented this and your answer is exactly what I wanted. Thanks!
icco
A: 

Hi

For a circle a perpendicular to a tangent would pass through the centre of the circle. Any line which passes through the centre of a circleis perpendicular to the tangent at the point it intersects the circle.

Regards

Mark

High Performance Mark
A: 

Hi

Ideally there can be infinite tangents to a circle and hence you can have infinite lines coming out of a circle.

If I did understand your question correctly then the following might help.

You can pick random points lying on a circle and then connect them to the center of the circle. For the lines to actually come out of the circle, consdier a circle of slightly bigger radius than your original circle, but having the same center coordinates. Then pick random points on the circumference of this outer circle and connect them to its center.

cheers

Andriyev
+1  A: 

I suggest you forget about the tangent and draw a line from the center of the circle in the directions you want the line to protrude from. You could offset the line the radius distance so that it starts at the edge of the circle.

corn3lius