2016-10-12

Minecraft is a land of Cubes. And yet, in this blockland, it turns out the circle is a very powerful tool. Using the basics of trigonometry, we can build all sorts of things.

Table of contents

BlockPos

Offsets

Other Shapes

Sine and Cosine

When a circle is drawn with it’s center at the origin of an axis,  the  coordinates for a point on the perimeter can be found using the Sine and Cosine Function.

A position on the ground in Minecraft is defined by the North – South position, Z and the East West position, X.  If your avatar walks from the origin along the Green line, the Red and Yellow lines represent the X and Z values.



This actually shows how we draw a circle.  If the Green line stays fixed at the center but pivots around it, the end of the green line draws the circle.

There area couple ways we measure the distance around a circle: degrees and radians. A circle can be divided up into 360 degrees, which is useful if you need to break the circle up into smaller pieces:  360 can be divided by many smaller integers to get 1/2, 1/3, 1/4, 1/5, 1/6, 1/8,  1/10 and multiples of those as well.   However, it gets less useful when we want to convert to Cartesian (X, Y, Z) coordinates.

Radians are based on the ratio of the radius to the perimeter of the circle.  This ratios is the number Pi, in greek π, which is roughly 3.14159.   P = 2πr.

Yeah, 2π.  They couldn’t make it a simple value.  Go read the tau manifesto.

Anyway, trig functions are defined in radians.  Halfway around the circle is π radians.  A complete iteration is 2π.

Oh, and because it all came from the ancient Greeks, we use another Greek letter for the angle:  Theta. which looks like this θ.

Wow, I wish we used tau.  But I digress.

If we are working in an X Y plane, there are two functions we can use that translate an angle in radians to the X and Y values of a point on the circle.  The Y is calculated by the Sine, and the X value is calculated by the Cosine.



BlockPos

Minecraft uses the Class BlockPos to indicate a position in the world. Creating a BlockPos

To place an Obsidian block at the origin in Minecraft we can use the following function:

If we want to draw a circle made of blocks in Minecraft, we can loop around the circle from θ = 0 to θ = 2π, and get the X and Y values (leave Z at 0).

Hooking it up to a command object, we can take a look at what it creates:



Vertical Circle at the Origin

Why is it only half a circle? Minecraft does not let us draw in the Negative Y space.

Offsets

Let’s add some code to allow us to move the center somewhere else, and to select a block to use to make the circle.

Now let’s try to generate a circle up and to the right of our origin.

Vertical circle offset from the origin.

Yeah, Red Wool came out White…wrong state.

If we want to draw a circle in the X Z plan (parallel to the ground, we can use the same logic, but vary the X and Z parameters, and leave Y fixed, like this:

And we get .

Horizontal Circles, one at the origin,. one offset.

Other Shapes

Once you get the basics down, you can add additional logic to generate disks…

with a star on them

Or stack multiple circles on top of each other to make a cylinder:

Cylinder of Mossy Stone

Or make the circles get smaller and smaller and make a cone:

Cone of Glass

Combining these tools you can get creative:

Childe Roland wuz heer.

If we combine the XY and XZ plane code, we can make shell of a sphere:

Finally, Add in some logic to make circles around the sine function.

Have fun.

Show more