0
$\begingroup$

The problem involves a circle inside a square sharing a common center point. The circle is always smaller than the square so that their edges never intersect. Then an annular sector (see cyan shape in Figure01) is sliced out in the area between the circle and square that consists of an indented arc (circle's edge) and two points (square's edge). The two points are what I am after amongst other things.

One important thing to bare in mind is that whatever angles are used to obtain the sector must also be offset by a certain amount as will become clear when you consider the magenta lines on Figure01 which represent the StartOffset and EndOffset respectively.

Figure01

Figure01

It is for a computer graphics function in Visual-Basic.NET so the user will input certain given values and from this the annular sector must be created.

Given:

  • StartAngle: Any valid degree between 0 and 360 (Left red line in Figure01).
  • SweepAngle: Any valid degree between 0 and 360 (Right red line in Figure01).
  • StartOffset: An amount of pixels to add to the StartAngle (Left magenta line in Figure01).
  • EndOffset: An amount of pixels to subtract from the SweepAngle (Right magenta line in Figure01).
  • CircleRadius: The radius of the circle (Indicated with yellow in Figure01).
  • SquareSize: The size of the square in pixels (Indicated with green in Figure01).

From these values the arc will be calculated on the circle's edge as follows. I merely need to give a starting degree and an amount of degrees to sweep so I calculate it as follows:

  • StartOffsetAngle = Asin(StartOffset / CircleRadius) * (180.0R / PI)
  • EndOffsetAngle = Asin(EndOffset / CircleRadius) * (180.0R / PI)
  • StartValue = StartAngle + StartOffsetAngle
  • SweepValue = SweepAngle - (StartOffsetAngle + EndOffsetAngle)

Then the two points that extends the arc to the square must be added and here is where the problems start:

First of all the radius to the StartAngle needs to be calculated for the square, but to do this the StartOffset needs to be added. To convert the StartOffset to degrees using Asin() the radius must be known. Is there a way to calculate these values and if so how?

The same problem goes for the other point, since the EndOffset needs to be subtracted.

Obviously when a corner in the square is overlapped there will be three points, but this is not my current problem, and should be easy to add.

Thanks

drifter

EDIT 1: I edited Figure01 based on the comments below. Hopefully it is clear now that the angle between the red lines and the angle between the magenta lines cannot possibly be the same. In the previous figure I tried to show the offset as a parallel chord, but it seems that was a bit confusing.

EDIT 2: Here is another image and some more explanation. Example

Basically the annular sector marked C is drawn by another function that uses two arcs. I can draw as many annular sectors outside of each other as I need without the offset between them sideways gradually increasing because the Asin(*Offset / *CircleRadius) is calculated for each arc. Now A and B has an *Offset indicated by D. This was drawn by hand, but when the function does it the offset grows gradually as it moves away from the center point (The black area gets wider). This is because I use a right angled triangle to get the radius to the outer points of A and B so that I can use Asin(*Offset / CalculatedSquareRadius) to calculate the offset angle with the correct radius. This seems to put me in an infinite loop (I Can't get the correct radius to the square without the proper angle that includes the offset and I can't get the correct angle without the radius). I also need to be able to calculate before I run the function how much the SweepAngle should be in degrees if I want it to represent a travel of 150 pixels on the square's edge.

$\endgroup$
  • $\begingroup$ Note that the angles $\theta$ and $\varphi$ are identical because the red lines are parallel to the magenta lines, right? $\endgroup$ – MPW Sep 19 '14 at 17:19
  • $\begingroup$ Not sure what you are asking, but the red lines are parallel to the magenta. The angle will be different since the red lines are the two angles the user asked for (i.e. 255° for 150 pixels), but the magenta lines are 2.5 pixels offset on either side. $\endgroup$ – user177305 Sep 19 '14 at 17:22
  • $\begingroup$ No, they won't be different. The angle between the red lines is exactly the same as the angle between the magenta lines. I'm not talking about the angle $225^{\circ}$, I'm talking about the angle between the lines, which is shown as a small red or magenta arc in the wedge of the sector. Aren't those arcs the $\theta$ and $\varphi$ you indicate? $\endgroup$ – MPW Sep 19 '14 at 17:31
  • $\begingroup$ @MPW Each magenta line is parallel to a red line. They are created by the function when it converts the StartOffset & EndOffset to angles and add/subtract them to the original StartAngle & SweepDistance. The angle will be different since the red lines are the two angles the user asked for (i.e. 225° for 150 pixels on the square's edge), but the magenta lines are 2.5 pixels offset on either side. The left-most magenta line becomes the left-most red line and the same for the other two as it where. $\endgroup$ – user177305 Sep 19 '14 at 17:40
  • $\begingroup$ A single line does not determine an angle. You must speak of two intersecting lines to have an angle. The angle formed between the two red lines IS IDENTICAL TO the angle formed between the two magenta lines. Neither of these angles is $225^{\circ}$. That's the angle measured clockwise between the positive horizontal axis through the center and ONE of the red lines. I'm giving up. I think you aren't being clear what the two labeled angles are. $\endgroup$ – MPW Sep 19 '14 at 17:51
1
$\begingroup$

Here's how you can compute it. Suppose you have a red ray $R$ from the center that hits the upper edge of the square at a point $P$, and suppose this ray deviates from the vertical ray upward from the center by an (absolute) angle $t$ (assume $t$ is sufficiently small that $P$ is away from the corners).

Then a magenta ray $R'$ parallel to $R$ but at a distance $\epsilon$ away from $R$ (you are using $\epsilon = 2.5$) will meet the upper edge of the square at at distance $d = \epsilon/\cos t$ away from $P$. This is true whether $R'$ is on the left or the right of $R$.

On the bottom, you would measure the deviation from a vertical ray downward from the center.

On the sides, you would measure the deviation from a horizontal ray leftward/rightward from the center.

Near the corners, it's harder. You'll have to extend the edges of the square and determine how much of the distance $d$ is actually on the edge of the square.

Note that the (absolute) deviation $t$ is no more than $45^{\circ}$, so the cosine is always positive.

So given this procedure, you can perform the analysis on both of the red rays in question. You have the distance, just be sure to add/subtract it correctly according to whether you are on the left/right side of the sector. I presume you know how to find the "ending" angle, given the "starting" angle (like $225^{\circ}$) and the distance $150$.

In your drawing, the magenta ray on the left side of the sector hits the upper edge at a distance of $$\frac{2.5}{\cos 45^{\circ}} \approx 3.536$$ from the upper left corner. That's point $D$ in your drawing.

EDIT: Now you have changed the drawing, which completely invalidates the geometry you insisted on earlier. The red rays are no longer parallel to the magenta rays. That renders this solution invalid. This was a lot of tedious explanation for nothing. Boo. :(

$\endgroup$
  • $\begingroup$ I apologize. I could see that my drawing completely misled everyone, but I am not a math person. I just need to work out how I can get the calculations to draw that simple cyan sector in the image when provided with the inputs under 'Given:' I can draw the arc, but the two points on the square is more complicated because it is a straight edge. $\endgroup$ – user177305 Sep 19 '14 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy