0
$\begingroup$

I'm defining an arc by calling a function like this: arc(x, y, radius*2, radius*2, start, end);

x: center x. y: center y. radius*2: width. radius*2: height. start: start angle in radians or degrees. end: end angle in radians or degrees. 

And now I need to "close" the arc by drawing two lines, both from the center of the arc, to the start and end point of the arc.

How do I find the start and end points?

  • 0
    @Sigur no I'm using Processing JS.2012-08-20

2 Answers 2

3

Given start angles and end angles you get

sX = offsetX + radius * cos(startAngle * PI/180) sY = offsetY + radius * sin(startAngle * PI/180) eX = offsetX + radius * cos(endAngle * PI/180) eY = offsetY + radius * sin(endAngle * PI/180) 

Multiplying an angle by PI/180 converts degrees to radians.

2

After reading http://en.wikipedia.org/wiki/Equation_of_a_circle#Equations as suggested by @rschwieb I came up with the following:

s_x = x+radius*Math.cos(startAngle*Math.PI); s_y = y+radius*Math.sin(startAngle*Math.PI); e_x = x+radius*Math.cos(endAngle*Math.PI); e_y = y+radius*Math.sin(endAngle*Math.PI); 
  • 0
    If your angles are in radians, you do not need the `Math.PI` factor. If your angles are in degrees, then you will need a factor of `Math.PI/180` instead.2012-08-22