1

I need to calculate the radius of a corner of a rectangle and the data I have to figure it out with is some points along the curve. Below is picture to illustrate:

3 points along corner

How do I calculate the radius from these three coordinates? Here is the data I have to work with:

middleY: 321.4
middleX: 272.625
top: 301
bottom: 341.8
left: 193
right: 352.25
0: x: 331.85, y: 301
1: x: 346.25, y: 306.95
2: x: 352.25, y: 321.4
3: x: 352.25, y: 341.8
4: x: 213.4, y: 301
5: x: 193, y: 341.8
6: x: 193, y: 321.4
7: x: 198.95, y: 306.95

I have sorted it out to corners (top corners are curved and bottom are not):

    {
      "topLeft": [
        { "x": 213.4, "y": 301 },
        { "x": 193,"y": 321.4 },
        { "x": 198.95,"y": 306.95 }
      ],
      "topRight": [
        { "x": 331.85,"y": 301 },
        { "x": 346.25,"y": 306.95 },
        { "x": 352.25,"y": 321.4 }
      ],
      "bottomLeft": [
        { "x": 193,"y": 341.8 }
      ],
      "bottomRight": [
        { "x": 352.25,"y": 341.8 }
      ]
    }

What I want to do is calculate the radius of the top left and right corners. I have found the radius of curvature formula, but I have no idea what to do with it, since I didn't take enough math to get there. :/

I am using Javascript, by the way, but I don't think that matters as much as just understanding how to use the algorithm.

6
  • 4
    Among the points shown as red dots, the corner radius is equal to the difference of either ordinate of the outside ones. Otherwise, it's their distance divided by sqrt(2).
    – Scruffy
    Commented Jun 12, 2021 at 1:52
  • 1
    "understanding how to use the algorithm" - which algorithm? Commented Jun 12, 2021 at 1:56
  • 3
    rounded rectangle edges always cover 90 deg angle so its enough to use the start and end point. For axis aligned rectangles its simple rx = |x1-x0|; ry = |y1-y0|; for circular arcs rx=ry otherwise elliptic ones are used ... for rotated ones you can use this Circular approximation of polygon (or its part) or un-rotate first
    – Spektre
    Commented Jun 12, 2021 at 6:35
  • "I have found the radius...": not sure what you are asking. Please provide expected output.
    – trincot
    Commented Jun 12, 2021 at 7:06
  • Yeah Spektre gave the simplest solution. Radius in sample data is 20.4. I.e.: 213.4-93, 321.4-301 etc. Trying to use curvature of line formula is really overcomplicating this. Commented Jun 12, 2021 at 14:42

1 Answer 1

0

This answer is in light of the comments on the question.

The corner radius in the picture shown, in terms of the points marked in red, is the difference of either ordinate between the outer points.

Here, ordinate means one of the values of a co-ordinate pair (x, y). So, if you have points (x_0, y_0), (x_1, y_1), the corner radius r = | x_0 - x_1 | = | y_0 - y_1 | where | · | is the absolute value.

1
  • Beautiful. In my case, the absoulte value of the x values wasn't the answer, but the absolute value of the y values. Thanks for your help, Scruffy!
    – HighHopes
    Commented Jun 16, 2021 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.