I have 2 lines that intersect at a point with know coordinates - x1,y1 - x2,y2 - x3,y3
From this I have calculated an arc at a given radius between the lines. So I now know - 2 arc endpoints x4,y4 and x5,y5 - arc centrepoint Cx,Cy - arc radius r - starting and ending angles relative to the X axis in polar and therefore the angle between the lines.
I want to create a formula that will calculate the maximum and minimum X and Y values of the arc. I.e. the coordinates of the box that would enclose the arc.
In the example below I can find out the minimum X value and maximum Y value, they are known values, but am unsure how to calculate the maximum X and minimum Y.
In other instances the arc could be any coordinates so the known minimum and maximum values will change.
I know how to calculate points along an arc at a given angle or intervals but not the maximum and minimum in a particular direction, in this case X and Y axis.
I am going to use the formula in programming.
Oleg Petrochenko's answer implemented in Javascript:
Here is a jsfiddle: https://jsfiddle.net/brunoimbrizi/y3to5s6n/45/
I have an algorithmic solution you can try using. It involves scanning the polar coordinate space in between your known starting and ending points on the arc, and keeping track of the minimum and maximum values.
Here are the basic steps of the algorithm:
I took advantage of the following two equations to convert polar to Cartedian coordinates:
Here is an equation to convert Cartesian coordinates to a polar angle:
You need to watch out for the potential divide by zero in this equation. Arc tangent of infinity is
Pi / 2
radians.This solution assumes that an arc begins and traverses counter-clockwise from a low radian value to a high radian value.
Testing
Suppose we have start angle θ1, end angle θ2 (both in radians), radus r, direction of the arc counterclockwise. We'd like to find Xmax,Ymax,Xmin and Ymin. Consider this values as functions of quadrants q=f(θ):
Xmax=f(q1,q2,r), Ymax=f(q1,q2,r), Xmin=f(q1,q2,r), Ymin=f(q1,q2,r).
Instead of writing huge number of "if" statements it's convenient to represent this functions as an "extremum matrices". Evaluating functions f(q1,q2,r) we'll end up with this matrices.
So here is the algorithm:
Here's my C#6 implementation:
It is fair for arc centre point at (0,0) but you can easily move resulting bounding box to your Cx,Cy.
Unlike Tim Buegeleisen's approximate solution this solution is exact, though it may be a little bit more memory expensive.
First find in which quadrant the endpoints are.
If they are in the same quadrant, then the arc is monotonic and the bounding box is easy.
Otherwise, each time you cross a quadrant, you'll get an extreme point that is an endpoint of a horizontal or vertical diameter.
Not too complicated to write an algorithm for that, though there may be several cases to consider, including the orientation of the arc.