DEV Community

Cover image for I needed a cone, so I built a cosplay pattern generator
Ramon Gebben
Ramon Gebben

Posted on Edited on AI-assisted

I needed a cone, so I built a cosplay pattern generator

I started a new cosplay: a human-sized gnome, a Nisse, like the little one that sits at the edge of my table.

gnome or Nisse

The hat is one big cone. Patterns for basic shapes online cost 3 or 4 euro, and I would still have to scale them to my size and hope the proportions held. So I drew it out and did the math myself.

Halfway through, I thought this should be simpler. There should be a website where you type in your measurements and the computer does the geometry, so you can trust the pattern you print. So I put the gnome down and started on that instead. A few hours later, the proof of concept was working.

That is CosplayShapes. Pick a shape and enter what you measured, and you get a true-scale PDF to print or an SVG for a cutting machine. It started with eight basic shapes and now has fifteen. What surprised me is that I barely had to start from scratch for the new ones. Every shape I got right made the next one a small step.

It starts with a fan

A cone unrolls into a fan: a slice of a circle. The radius of that circle is the slant of the cone, from the tip down to the base. The curved edge has to be exactly as long as the base circumference, so the angle of the fan is the circumference divided by the slant.

const slant = Math.hypot(midRadius, midHeight);
const sweep = (TAU * midRadius) / slant;
const { outerArc, outline } = sector(slant, 0, sweep);
Enter fullscreen mode Exit fullscreen mode

TAU is 2π, one full turn in radians, so TAU * midRadius is the circumference.

That was the hat. But I wasn't making it from paper. I was making it from 6 mm EVA foam, and foam bent into a cone is longer on the outside than on the inside. If you cut the pattern to the size you measured, the finished hat comes out too small.

So the app draws every pattern at the middle of the material, half the thickness further out than the form it goes around. That is the mid in midRadius and midHeight. For a hat 22 cm around and 15 cm tall, a paper cone has a 15.4 cm seam. In 6 mm foam the app makes it 16.8 cm, with an arc angle of 81.8°.

The cone page on a phone: a yellow cone model above its fan-shaped flat pattern

That one rule, measure at the middle, came along into every shape after it.

Cut a hole in the fan

The 0 in sector(slant, 0, sweep) is the inner radius. A cone with its tip cut off, a truncated cone, is the same fan with a smaller arc cut out of the middle. Carry the slanted wall on until it meets at a point, and you know the radius of the full fan. The inner radius is that minus the slant.

So the pattern for a bracer or a hat brim was one extra argument.

The truncated cone page on a phone: a tapered tube above its curved band of a pattern

Slant a tube, then stack it

A cylinder unrolls into a rectangle. Cut its top on a slant, and going round the tube, the top rises from the short side to the tall side and comes back down. Unrolled, that edge is a cosine wave:

const heightAt = (x: number) =>
  middle - midRadius * slope * Math.cos((TAU * x) / width);
Enter fullscreen mode Exit fullscreen mode

That gave me the angled cylinder. It also gave me something better. Put two of those slanted ends together, and the tube turns a corner. Each side is cut at half the angle of the turn, and the two waves meet exactly. That is one joint of an elbow, the kind you see on a lobster-back pipe. Stack a few sections, each slanted at both ends, and you have a bend as smooth as you want.

The elbow page on a phone: a bent yellow tube above its section patterns with wavy ends

Put the cone and the elbow together

Now I had a shape that tapers and a shape that bends. A horn does both. So the curved horn is an elbow built from cone sections instead of cylinder sections, all with the same taper.

This is the one step that didn't come for free. A cylinder has the same radius everywhere, so two of them cut on the plane halfway between their directions meet in the same ellipse. A cone gets narrower towards its tip. Cut two neighbouring cone sections on that same halfway plane, and their edges come out a slightly different size. The glued seam would gap.

What makes it work is a sphere. Place the sections so that, where their axes cross, they have the same radius. Then a single sphere sits snugly inside both cones at that point, touching each of them all the way round. Two cones that touch the same sphere meet in a flat curve, so there is a plane that cuts both edges to the same shape. That plane faces the same way as the halfway plane, shifted a little towards the tip by an amount that follows from the taper and the turn.

I wasn't going to trust that to a drawing. The tests take points along each cut and check that they lie on both neighbouring cones, and that the two edges you glue together are the same length.

The curved horn page on a phone: a curling, tapering yellow horn above six section patterns

Stop thinking in spheres

Domes and spheres are cut as gores, the long pointed pieces of a beach ball. My first version could only cut gores from a sphere. A dome was the top of a sphere, and the width of a gore came straight from the sphere's formula.

The oval dome broke that, because an ellipse isn't a sphere. Instead of adding a second formula, I changed the question. Any round shape can be described by its outline from the top down: its profile. Walk down that profile, and at every point you know how far you have come, and how wide the shape is there. The gore is exactly that far along, and as wide as that circle divided between the gores:

const halfWidth = (radius: number) => (Math.PI * radius) / gores;
Enter fullscreen mode Exit fullscreen mode

Once that worked, a new round shape was only a new outline. The oval dome is a quarter ellipse, and a capsule is two half circles with a straight piece between them. The sphere and the dome moved over to the same code, and a pointed dome came out of the same afternoon.

There is one catch. "How far you have come" becomes the length of the seam, so it has to be exact. Measuring a curve with straight chords always comes out a little short. The error shrinks with the square of the chord's angle, so measuring with 8 chords and with 16, and combining the two, cancels most of it:

(4 * chordSum(segment, from, to, 16) - chordSum(segment, from, to, 8)) / 3
Enter fullscreen mode Exit fullscreen mode

For a circle, that is exact to well under a micron.

Printing it

All of this only matters if the pattern prints at the right size. The PDF starts with a guide page holding a calibration square, so you can check that the printer didn't scale the page. Large pieces are tiled across pages with crosshairs to line them up, and the guide page has a QR code back to the exact pattern, so you can find it again when you start the second horn.

The CosplayShapes picker with the basic shapes: cylinder, cone, truncated cone, dome and sphere

It's free, with nothing to sign up for, and the code is MIT licensed.

The gnome is next. The hat pattern is ready.

Top comments (0)