4/4/2023 0 Comments Maximize xlist box![]() ![]() Y = h/2 - (boundingBox + boundingBox) * radius / 2 Solving for x and y, the center of the arc, gives x = w/2 - (boundingBox + boundingBox) * radius / 2 (boundingBox + boundingBox) / 2 * radius + y = 圜enter = h/2 Now we'll create another linear equation: (boundingBox + boundingBox) / 2 * radius + x = xCenter = w/2 ![]() Now we have to place the center of the arc. xRadius and yRadius can't both be 0 because both sin and cos would have to be 0 for all angles included above for that to be the case. If you don't have an infinity available, you can just set it to 0 and in the MIN function, check for 0 and use the other value in that case. This will give the correct result as yRadius will be smaller. Here, you have to check for boundingBox - boundingBox being 0 and set xRadius to infinity in that case. YRadius = h / (boundingBox - boundingBox) Solving the equation gives: xRadius = w / (boundingBox - boundingBox) Since your algorithm asks for only one radius, we will just pick the lower of the two values. The reason for that is that in order to fill the rectangle, we have to multiple by different amounts in the two directions. To fill the box, we're going to have to solve a linear equation: boundingBox * xRadius + xOffset = 0Īnd we have to solve for xRadius and yRadius. Now you've computed the bounding box of an arc with center of 0,0 and radius of 1. The start angle, the end angle, and potentially, the cardinal directions (there are 9 of these going from -2 * PI to 2 * PI.) I'm going to define boundingBoxes as lists of 4 elements, ordered def IncludeAngle(boundingBox, angle)ĭef CheckAngle(boundingBox, startAngle, endAngle, angle):ĬheckAngle(boundingBox, startAngle, endAngle, -2 * PI)ĬheckAngle(boundingBox, startAngle, endAngle, -3 * PI / 2)ĬheckAngle(boundingBox, startAngle, endAngle, -PI)ĬheckAngle(boundingBox, startAngle, endAngle, -PI / 2)ĬheckAngle(boundingBox, startAngle, endAngle, 0)ĬheckAngle(boundingBox, startAngle, endAngle, PI / 2)ĬheckAngle(boundingBox, startAngle, endAngle, PI)ĬheckAngle(boundingBox, startAngle, endAngle, 3 * PI / 2)ĬheckAngle(boundingBox, startAngle, endAngle, 2 * PI) However, you really only have to include up to 11 points in this calculation. Of course, angle is a range, so it's not as simple as this. You need to calculate 4 numbers: Left: MIN(cos(angle), 0) So, the algorithm that comes to mind is to calculate the bounds of the unit arc and then scale to fit your rectangle. For this algorithm, I assume that startAngle endAngle, I would do: if (startAngle > endAngle): Instead of pseudo code, I used python, but it should be usable. calculate the final axis-aligned bounding-box (AABB) find x & y from the radius and minimum extrema calculate the maximum radius the fits in the bounding box If wrap(t0-math.pi) > wrap(t1-math.pi) then Here is an implementation written in Lua: - ensures the angle is in the range [0, 360) Given the extrema of the axis-aligned bounding box of the arc (x0, y0), (x1, y1) the radius and center point can be calculated as follows: r = min(w/(x1-x0), h/(y1-y0) 0, 90, 180 and 270 degrees) and the end points of the two line segments. The values x0, x1, y0 and y1 are found by taking the minimum and maximum values of up to 7 points: any tangential points that are spanned (i.e. The extrema of the bounding box of your arc are in the following format: x + x0 * r = 0 Pseudo code would be great since I'm not a big mathematician. I am searching for an algorithm which determines center of the slice and radius in a way that fills the rectangle best. This is fairly easy for the cases I've sketched but it becomes complicated when the start and end angles are arbitrary. A good solution here would be to move the center point to the top left of the rectangle and to set the radius to the smaller of both rectangle sides.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |