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.

HighHopes
  • 2,014
  • 3
  • 23
  • 33
  • 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 Jun 12 '21 at 01:52
  • 1
    "understanding how to use the algorithm" - which algorithm? – Jaromanda X Jun 12 '21 at 01: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)](https://stackoverflow.com/a/27251997/2521214) or un-rotate first – Spektre Jun 12 '21 at 06:35
  • *"I have found the radius..."*: not sure what you are asking. Please provide expected output. – trincot Jun 12 '21 at 07: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. – Peter Dongan Jun 12 '21 at 14:42
  • @Scruffy that was the answer! You used the word "ordinate" and I had no idea what the meant. But after looking it up I realized it was just the y corrdinates of the outside points. If you will add that as an answer, with an explanation of what odinate means, I will mark it as correct. – HighHopes Jun 14 '21 at 15:37

1 Answers1

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.

Scruffy
  • 580
  • 8
  • 23
  • 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 Jun 16 '21 at 20:19