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.
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.
- 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.
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.
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.