Assuming the arcs are centered at the origin, the coordinates of the box would be (r, r), (r, -r), (-r, -r), and (-r, r), where
.
I don't understand why you would need two angles.
Hi. First post here. Hope I don't break protocol...
I am writing software to convert a display list file into a different display list file format (conceptually similar to HTML, for those who care). The display list files use differing ways to describe arcs, and I need to transform from one to the other. Both use a Cartesian coordinate system to define the drawing space.
My input file describes arcs in terms of a start-point (x0,y0), end-point (x1,y1), and a central angle (a). I need to transform the arcs described in the input to a format that uses a starting angle (c), a total angle (d), and the coordinates of a bounding box whose sides are tangent to the circle that would complete the arc.
I would like to know how I can make such a translation; at least some pointers to the key rules that I can use.
This is not homework, just to clear the air on that matter. Feel free to correct any jargonolgy errors.
Thanks,
--- rod.
The centre point is completely unknown, and will almost never be at the origin. As for why the need for two angles, well that is what the program that reads and renders the display list file requires. This is not an aspect left for me to specify. I guess you could specify the starting and ending angles of the arc, which is really the same thing.
Thanks for responding.
--- rod.
Upon reflection, I think I can restate my problem, removing my own problem domain, and creating a generic mathematical question. Here goes...
Given an arc with start-point, end-point, and central angle, what is the center point and radius of the arc?
Clearer, no?
--- rod.
I have your answer, but it is probably more complicated than you are going to like.
You have three unknowns: which is the circle center, and , the circle radius. You know your two points and the central angle assumed to be in radians (in your picture above, what I'm calling is actually . Your is the angle of the major arc, while is the angle of the minor arc). You have the equations:
So far so good. Two equations for 3 unknowns - we are almost there. Now to incorporate the central angle information. Recall the law of cosines. From this we can derive that
where is the distance between and . So we have
(Let me know if you have questions about this derivation - it follows pretty quickly from the law of cosines.)
We now have three equations and three unknowns. I don't even want to try solving this thing by hand - you can have fun with that if you want. Instead, we can solve this non-linear system of equations using a computer, for example in MATLAB (if you have to program this yourself, I suggest you use a modified Newton's method or the like as described in Numerical Recipes).
In MATLAB, fsolve is used for finding an x that is a solution to the system of non-linear equations . The syntax is
where fun is a function reference, and x0 is an initial guess.x = fsolve(fun,x0)
Here is a function in MATLAB that solves your problem:
You can now run this in MATLAB with the syntax.function F = test( x, x_1, y_1, x_2, y_2, c_A )
x_c = x(1);
y_c = x(2);
r = x(3);
F = zeros(3,1);
F(1) = (x_1 - x_c)^2 + (y_1 - y_c)^2 - r^2;
F(2) = (x_2 - x_c)^2 + (y_2 - y_c)^2 - r^2;
F(3) = (x_1 - x_2)^2 + (y_1 - y_2)^2 - 2*r^2*(1 - cos(c_A));
end
Here fun = @(x)test(x,3,5,-3,5,c_A) is the function pointer, and x0 = [1,-1,pi/2].A = fsolve(@(x)test(x,3,5,-3,5,acos(7/25)),[1,-1,pi/2])
I setup a problem where I know the answer to test this. If you choose and , you can choose the points and . This gives .
If you run this in MATLAB, you would get the output:
which are the parameters I used to create this example. Success!EDU>> A = fsolve(@(x)test(x,3,5,-3,5,c_A),[1,-1,pi/2])
Optimization terminated: first-order optimality is less than options.TolFun.
A =
0 1.00 5.00
Hope this solves your problem!
Ok, ok, I finished it. Bad news: there are two possible solutions. This makes sense if you think about it - if you have the same radius and the same central angle, you can have the center in either the positive or negative direction.
Here's the solution:
Let:
Here is the distance between the two points, is the slope of the line connecting the two points, and is the mid-point between the two points.
Giving:
So, unless you have some more information, looks like your solution is not unique. In my example above, the center can either be at or .
This breaks if . In that case,
Many thanks for your thorough explanation and analysis. I'm sure I will need at least an order of magnitude more time to digest it than it took for you to compose it. I feel certain I will followup with more questions.
The conclusion that the solution is non-unique is a bit disconcerting. Is it possible that I can discern the desired solution from the order of the end-points (or the 'direction' of the angle, to put it another way)? The software that visually renders these data is sensitive to the order in which they are read in the input, hence my description of 'start' and 'end' points.
Thanks.
--- rod.
You are welcome. Take your time and follow up with as many questions as you like. This was a fun problem for me.
Ok, so the order does matter. That's a start. If you can say if the central angle is measured clockwise or counter-clockwise, I'll tell you which solution to use. That would give enough for a unique solution.
Make sure you tell me if the orientation is for the minor or major arc.