Obround Formulae

An Obround is essentially two semicircles connected continuously with parallel lines. That’s the dictionary definition of it, but I like to think of it more as the radius of a single line. Here’s an example image to show what I’m talking about:
image

Now this is a fairly important shape when it comes to calculating hitboxes, and should be computationally easy for the computer to handle. I will be breaking down how to go about computing this shape in two dimensions.

Firstly, we need to make a line before we get the radius around it. Ideally, the start and end points will be given, so we’ll just say that there’s some point (x1,y1) and another point (x2,y2) that we want to make the Obround around. In order to connect these two points with a line, we will need to know the slope between them, which is simply given by the formula (y1-y2)/(x1-x2). Note that whichever xy pair goes first doesn’t matter, the resulting slope will be the same regardless. Now that we have the slope, we can then plug it into the formula y-y1=m(x-x1) which simplifies to y=m(x-x1)+y1. Again, whichever point pair gets used does not matter. The resulting line will intersect both points, as shown below.

Now we also have this point (x3,y3), that we want to check is inside the Obround. Its slope is going to be the negative inverse of our previously found slope, as that will give us a line that is perpendicular to the Obround line, which is the shortest path to the Obround. This will give us the formula y=(-1/m)(x-x3)+y3, shown below.

In order to get the point that intersects both lines is, we need to have both the y and x values will be equal. Fortunetly, we already have formulas for where the y values will be, so if we set them equal to eachother we will find what the X value will be when the Ys are equal. This gives us the formula m(x-x1)+y1=(-1/m)(x-x3)+y3, which can be set to mx-mx1+y1-(-1/m)(x-x3)-y3=0. We can multiply all the values by m to extract that (x-x3), giving us mmx-mmx1+my1+x-x3-my3=0. Move all constants to the right hand side, giving us mmx+x=mmx1-my1+x3+my3. mmx+x can be rewritten as (mm+1)x, so if we divide both sides by mm+1 we get x=(mmx1-my1+x3+my3)/(mm+1). This gives us the X component of the intersection point. Fortunetly, finding the Y value isn’t as tedious, as you can simply plug in this X into either formula (I’d suggest using y=m(x-x1)+y1). You can then bring both X and Y components into a single point (x4,y4), as shown below.

Now how do we get the magnitude between this intersection point and the target point? We use the Pythagorean theorem of course! This should be fairly straightforward, all you need to do is subtract the two points’ X and Y components, square each component then sum and square root, which should give the following: dist=sqrt(x3-x4)^2 + (y3-y4)^2). You can usually forgo the square root if you want greater performance, just remember to square the radius as well before comparing the two values.

Explain it in Fortnite terms please.

image

What is blud yapping

1 Like