Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Making circles (and polygons) that fit textures properly

Recommended Posts

I posted this half-jokingly in the latest Abyssal Speedmapping thread, but maybe some people will actually want to see it, so I'm posting it here too.

The diameter of a circle is equal to it's circumference divided by pi.

If you want a circumference of 256 units for example, which would fit a 128px texture twice, then you want a diameter of (256/pi) = 81.4873 units. Round to the nearest even number (82), because you want a radius that is a whole number for working in DB.

Draw a line that is 82 units wide, then two more lines (any size, doesn't matter) to form a triangle. Click the 82 unit line and then click the curve linedef tool. Choose an odd number of vertices, an angle of 180 degrees, and check "Fixed circular curve". You should get a half-circle. Delete the vertex of the other two linedefs so that the triangle collapses and gives you a new diameter line, then repeat the process.

Draw two lines between the top and bottom points, two more between the left and right points, to form a cross. If you want, join the new sectors and delete all but one linedef from the cross. This will give you a 41 unit radius line that you can use to centre your circle on a specific point. Or just draw the radius line yourself if you find that easier.

Now you can use DB's auto-align on that circle and it will give you an evenly-tiling texture.

Regular polygons (e.g a hexagon) can use the same formula and get pretty close, especially if you have a large number of sides. There are more precise equations for polygons, which I'll post if anyone wants.

Share this post

Link to post

Hm, this will be pretty useful for giving maps a circling sky effect on skyboxes without the texture seam, pretty cool.

Share this post

Link to post

I've been doing some trigonometry stuff but none of my general solutions for a given radius/diameter, and number of vertices are very elegant. In your initial post you mention precise equations for polygons; I would be very appreciative if you could give said formulae.

Share this post

Link to post

Sure. It's a bit messier than with circles, the process varies depending on the number of sides and orientation of your polygon. Apologies for being lazy with images here and just using the first things that come up when I search google. :P

  • r: radius, distance from the centre of a polygon to a vertex. Polygons don't really have a diameter, so I'll use 2r for two radii (radiuses).
  • a: apothem, distance from the centre to the middle of a side.
  • p: perimeter, the sum of the distance of all sides.
  • n: number of sides.
  • x: used for the angle between a radius and one of its nearest apothem. Calculated as (180/n), in degrees.
  • s: length of a side, calculated as (p/n). Unneeded for the formulas but good to know anyhow.
The formula(s):
  1. 2r = p / (n * sin(x)) - this is the important one

    These others are just for reference or if someone is doing non-Doom geometry, for some reason.

  2. 2a = (p * cot(x)) / n
    note: cot(x) = 1/(tan(x))

  3. r + a = (p * cos(x) + p) / (2 * n * sin(x))
Assuming your polygon is in some way aligned to the X or Y axis, there are three cases to consider.
  1. n is an even number but not divisible by 4, e.g. n=6 (a hexagon). You will always have one axis aligned with a radius, and one axis with an apothem. Working with the radius is easier, so you can always do that.

  2. n is an even number and divisible by 4, e.g. n=8 (an octagon). Depending on the orientation you want, the X and Y axes will align with either radii or apothems.

  3. n is an odd number. A single axis will align with both an apothem and a radius. There are four possible orientations here.

Examples! In all cases I'll use p=256 - fits a 128px texture twice.

n=6 (first case)

Pick an orientation. In the first example, the radii will go horizontally, from left to right; in the second, vertically from top to bottom. Here I'll use the first. Then calculate x and s, and then use the first formula.

x = 180/6 = 30
s = 256/6 = 42.667

2r = 256 / (6 * sin(30)) = 85.333. (You can see it's pretty close to d for the circle.) As before, round to the nearest even number, in this case 86, so that r is a whole number 43. (In some cases rounding to the other side, e.g. 84 here, gives you better accuracy overall. Don't know the best choice besides trial and error I'm afraid!)

Draw an 86 unit line, horizontally in this case, and then two other lines to make a triangle as before. Click the 86 unit line, choose curve linedef, and set the number of vertices at (n/2) - 1, in this case 2. Angle should be 180 and fixed circular curve should be checked. Delete the other vertex to get another 2r line and repeat. (Or just copy one half of the polygon and flip it if you prefer.) There's your hexagon!

There's always going to be a bit of error due to vertices needing to be on integer coordinates. Here, two lines are 42 units long and the other four are 43.05, which sums up to 256.2 - not bad!

n=8 (second case), apothems aligned with axes

x = 180/8 = 22.5
s = 256/8 = 32

If the radii were aligned with the axes, the process is basically the same as above. But for the apothems aligned you've got to do things a little differently. The second formula doesn't exactly work, because DoomBuilder's curve tool works with the lines starting from corners.

Instead, start with the first formula again.
2r = 256 / (8 * sin(22.5)) = 83.62, round up to 84.

(The more sides you add, the closer that 2r will get to the circle's diameter. But that's getting into calculus, and this post is mathy enough already.)

Repeat the process of drawing a triangle with one side at 84 units, then curving it - except this time, choose the number of vertices at n-1, in this case 7. Repeat for the other side. You've now got a polygon with 16 sides... and you can just delete every other vertex to get it down to 8 sides.

Four sides are 32 units, four are 32.53, for a perimeter of 258.12 - not bad, maybe less error if you rounded the 2r line down to 82 instead?

Repeating the process, four lines are 32 units and four are 31.11, sum of 252.44. Worse, but sometimes it's better to have a perimiter that is too short rather than too long, depending on the texture.

n=5 (third case)

Again there are two possible orientations for the "centre line" (apothem + radius). But then there are also two options for whether the radius is on the top/left or bottom/right.

x = 180/5 = 36
s = 256/5 = 51.2

Use the first formula again (ignore that we don't actually want 2r), and then draw the triangle as before, with the centre line along the correct axis.

2r = 256 / (5 * sin(36)) = 87.11 ~ 88

Again, curve the 88 unit linedef with vertices set to n-1 = 4. Like before, you draw twice as many lines on each side and then delete every other vertex. In this case, the choice of vertices to delete will determine which direction the pentagon is pointing.

Anyhow, after doing that I get sides of 52 + 52.5 + 52.5 + 51.61 + 51.61 = 260.32. A bit high; with 2r = 86, 252.8, which is maybe better.

I think that covers it! Hopefully that makes some sense and isn't too hard to follow for anyone. Maybe I'll do some example wads later that have each steps.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now