All posts by Neil

Lego Technic Triangle Geometry

Time for some fun with Pythagoras!

Lego tends towards rectangular constructs, but sometimes we might want to make triangular connections. Technic beams especially lend themselves to this.

Right-angled pythagorean triangles are fairly easy to construct. Here’s a 3,4,5 triangle:

345t2an

Notice that when you build it you build it as 4,5,6. That’s because it’s the distance between the pin centers that has to be in the 3-4-5 ratio. Two pins separated by 2 holes are a total distance (center-to-center) of three holes apart. Or said another way, two pins right next to each other are distance “one unit” apart, not two. Thus: A two-hole beam would be a distance of “one unit” in this analysis.

There are many pythagorean integer triangles. Here’s the complete list up to a reasonable size:

  • 3-4-5 (also 6-8-10, 9-12-15, 12-16-20 etc)
  • 5-12-13
  • 7-24-25
  • 8-15-17

If you try to build these don’t forget the +1 factor for counting holes.

If we allow half unit offsets there are some more pythagorean triangles available. Obviously any of the above constructs can be divided in two; beyond those we also have:

  • 4.5-20-20.5
  • 6-17.5-18.5
  • 7.5-18-19.5
  • 10-10.5-14.5
  • 12-22.5-25.5
  • 13.5-18-22.5

In the 3-4-5 family the angle opposite the “4” side is 53.13 degrees. The reason this is good to know is that the standard bent beams are at that same angle (53.130) and now you know why:

53p1angle-1024x668

If you build this you will see that the angles match up perfectly.

If you combine a pythagorean triangle with its mirror you will get an isosceles triangle. Here, for example, is a 6-5-5 construction which is two mirrored 3-4-5 triangles

655iso-1024x668

Notice, once again, you build 6-5-5 as 7-6-6 if you are counting the total number of holes in each side. This kind of construction will be very strong and also has the advantage of being able to attach things to the vertical riser in the spine of the triangle and have them be “on grid” whereas the holes in the angled beams are rarely ever “on grid” except at the vertices.

Trapezoid Extension – Pythagorean

Once you can make a triangle, you can make a corresponding trapezoid by extending it evenly in one dimension. This is easy to do for right (pythagorean) triangles:

345quad-an

Here I took a 3-4-5 triangle and extended out the base (by 4 in this case; “n” as shown in the diagram). I have to extend the connection point up top out the same amount. The geometry still works and everything lines up.

We’ll revisit this topic for non-pythagorean triangles in a moment; there are some triangles that you can extend into trapezoids and some that you can’t (easily).

System Brick Triangles

You can make triangles using system (“standard lego”) bricks too:

system-pyth

Note how I used two 1×1 bricks to create “pylons” for the angled brick. You have to do this, or something similar, because the neighboring studs will interfere with the angled piece.

General Triangles

Any three beams that satisfy the triangle inequality can be formed into a triangle. In general you will need to use four beams in the construction because you need to “jump” up/down one level to make the last connection work. Look at the construction of the 3-4-5 pythagorean triangle to see an example of why 4 beams are needed (and in that case since one of the joints is a 90 degree angle I used a T piece but in general you will want to use just straight beams when making angles that are not 90 degrees).

The lengths of the triangle sides will determine the angles according to standard triangle side-side-side (SSS) solutions. Just hook them together and let the angles fall where they may.

Of course, we might like to know what those angles actually are. I wrote a small python program that calculates Lego triangle angle information for a given configuration of sides. The source is available here: http://neilwebber.com/files/legotriangles

If you prefer, here is the table of output it generates for full-unit constructions and half-units:

You can use the command line options (read the source) or just peruse the uploaded table and see that there are some other useful angles you can construct, though in some cases you will have to settle for close approximations. For example, there is no 45 degree construction but there are two that come close:

  • 5-12-15 will generate an angle of 45.036 degrees.
  • 13-17-17 generates 44.959

Any equilateral construction generates 60 degrees but so do these:

  • 3-7-8
  • 5-7-8

Here’s a 3-7-8 construction. The angle between the blue and red beams is 60 degrees.

378d60-1024x668

This construction also more clearly illustrates the need to use four beams (not just three) to make a triangle because of how the “levels” at the vertices work out. One of the sides has to jump back down in order to join with the remaining side.

Because of that 60 degree angle, that implies you can build a 3-7-8 connection across an 8-8-8 equilateral triangle:

378d60eq91-1024x668

The angles opposite the blue beam (both above it and below it) are both 60 degree angles (by definition because the outer frame is an equilateral triangle). This construction is probably demonstrating some deep mathematical relationship between the 3-7-8 60 degree construction and the 5-7-8 construction; perhaps someone will point it out to me and I’ll add it back into this note.

If you have a larger equilateral triangle you can still make this connection at this point near the vertices or of course you could scale up the 3-7-8 or 5-7-8 as appropriate (possibly using half unit constructions too if necessary).

Don’t forget (in case you are confused again): building something with a 3-7-8 relationship takes hole counts of 4-8-9. You can count the holes in the above picture and verify this.

Non-pythagorean Trapezoids

Let’s look at a 4-8-10 triangle (which would be equivalent to a 2-4-5 triangle but this is easier to construct):

4-8-10t

As always: built as 5-9-11.

The angles on this triangle are 22.332 (between blue and yellow), 49.458 (between blue and red), and 108.21 (between red and yellow).

Let’s say we want to make a trapezoid out of this. We can, for example, extend the blue beam to the right by making it longer, and finish out the rest of the trapezoid with right angles:

4-8-10tz

but, as you can see, we have a problem with the final joint at the red/yellow (and pink) vertex. That point isn’t on grid, whereas the pink beam, the black “riser” L piece, as well as the blue base are all on grid.

We can calculate the location of the red/yellow vertex using standard trigonmetry. Using the yellow/blue vertex as the origin, the X and Y coordinates (X along the blue beam) of the end of the yellow beam will be:

X = 8 * cos(22.332°) = 7.4

Y = 8 * sin(22.332°) = 3.04

NOTE: It’s “8” because that’s the length of the yellow side of the triangle.

The vertex doesn’t even line up vertically even though it looks like it might. It’s just close. It definitely doesn’t line up horizontally. We have no way to make that final connection.

Generally speaking you can’t easily extend non-pythagorean triangles into grid-legal trapezoid constructions.

A few constructions come very close; whether you want to use them in your models is up to you. They aren’t “on grid” but any given construction always has a certain amount of play in it and if they are close enough then things will appear to work. I believe the Lego corporation would refuse to accept these constructions as part of a design for a set, so in that sense they are “illegal”.

Here’s one that comes very close. Take the 3-7-8 triangle we saw before:

378d60-1024x668

Taking the blue base as the X axis and the blue-red vertex as the origin, we can calculate the location of the red-yellow vertex. We already know that the angle between the red and blue is 60 degrees (you can reverify this using my tables or perform your own SSS triangle solution for 3-7-8; the angle opposite the 7 side is 60 degrees). Since the red leg is 8 units in length the location of the red-yellow vertex is:

X = 8 * cos(60°) = 4.00

Y = 8 * sin(60°) = 6.93

 

The X coordinate works out evenly on-grid, thanks to the cosine of 60 degrees being exactly one half. The Y coordinate is off grid but close enough that the following construction will appear to work:

trapz60

In reality the pink beam is at (relative) height 6.93 on its left end and 7.00 on its right, thus there is some stress/flexing in the construction to make it work. You might reduce that stress slightly by only pinning the pink beam with one pin at the right end (vs the two shown in this build).

This just happens to work out as a case where the off-grid amount is smaller than the inherent flex in the pieces. Your mileage may vary; personally I don’t use these non-aligned constructions in my models but I present this as being one that is very close to ok. You can find others generally by doing math or by just trying things to see what works within reason.

Going back to the 4-8-10 (5-9-11) construction, there is a way to make a trapezoid out of it, like this:

4-8-10tzgood

because what I did here is just extend the base, then insert a parallel corresponding extension (the black beam), and connect them with a beam (the second red beam) that is parallel to the original side of the triangle. This preserves all the geometry and gets everything lined up in the right spot; however, in this entire construction only the blue beam is “on grid”; everything else is at non-standard locations.

This structure is quite stable and reasonably strong though I’d be cautious about putting too much weight or pressure on it from top (perhaps someone will work out the statics on this one; just going by feel it seems reasonably strong but I’m not sure exactly where the forces are going when it is put into compression that way).

Approximate “standard” angles

I already listed two constructions that are very close to a 45 degree angle; here is a more complete list of approximations to common/useful angles.

30 degrees (approximate)

a b c ∠° Error Comments
3 5 6 ∠A = 29.9264  0.0736°  should prefer 4 7 8 usually
4 7 8 ∠A = 29.9947  0.0053° closest / smallest
7 12 14 ∠A = 29.9947  0.0053° same angle as 4-7-8; larger

Of course multiples of those triples works, so for example 8-14-16 is another good 30 degree approximation (doubled from 4-7-8).

Half-unit constructions can get even closer:

a b c ∠° Error Comments
5.5 9.5 11 ∠A = 29.9996  0.0004°
5.5 14.5 19 ∠B = 29.9996  0.0004° same angle as 5.5-9.5-11 which is easier to build.
7.5 13 15 ∠A = 29.99997  0.00003° nearly “exact” for all practical purposes.

The 7.5-13-15 triple can be looked at as half of a 15-15-15 equilateral triangle. A point 7.5 along one leg is halfway; if we then went exactly 90 degrees up to the other vertex we should have a height of:

  h = 15 * sin(pi/3)                     # (pi/3 = 60 degrees in radians)

which computes out to h = 12.9904. So our actual height of 13 won’t form a true half of a true equilateral triangle; it will resolve to angles that are slightly off in all spots, but based on how close 13 is to 12.99 you can see why building the triangle at 7.5-13-15 gets so close to the 30 degrees.

If you really need an exact 30 degrees you can get it from the complementary angle on an equilateral construction or from any of the other exact 60 degree constructions (see table lower down).

45 degrees (approximate)

There aren’t any 45 degree approximations that are as close as the 30 degree ones unless we allow half unit constructions. Here is the table of some useful ones including half-units:

a b c ∠° Error Comments
3 19 21 ∠B = 45.06135 0.061°
5 12 15 ∠B = 45.03565 0.036° best/smallest integer construction.
6 12.5 16 ∠B = 45.00612 0.006° very good; see 8-8.5-12.
8 8.5 12 ∠B = 45.00612 0.006° Same ∠ as 6-12.5-16 but smaller. Second best known.
9.5 14 19 ∠B = 45.00349 0.0035° Best (but uses half-units).
11 18 24 ∠B = 45.05405 0.054° 5-12-15 is a better integer construct.

60 degrees

You can, of course, easily get 60 degrees from any equilateral triangle construction (all sides equal). You can also get it from the complementary angle on any of the above 30 degree constructions.

There are quite a few triples that lead to exact 60 degree angles. Here are a few of the simpler and more likely useful ones (including half units):

a b c Comments
1.5 3.5 4
2.5 3.5 4
2.5 9.5 10.5
3 7 8 Just double 1.5-3.5-4
4 6.5 7.5
5 7 8 Just double 2.5-3.5-4

NOTE: In all of these, it is angle B that is the 60 degree (exact) angle.

41.4096 degrees

Say what? Well, the cosine of 41.4096 is 0.75, which means that a beam on this angle will generate a half-unit offset at two holes and every four holes thereafter.

Is this useful? I’m not sure. There is a problem that the sine (0.6614) is nothing useful, so this means that while your beam will have holes at half-unit offsets in one dimension, the other dimension will never be on-grid. Nevertheless, for your amusement, I present this table:

a b c cosine Comments
2 2 3 cos(∠A) = 0.75 exact Isoceles; angle B also works.
3 8 10 cos(∠B) = 0.75 exact Note this one is angle B
4 5 6 cos(∠A) = 0.75 exact

Here’s an example 2-2-3 construction, with the orange lines showing which holes (in the blue beam) are on half-unit offsets from the adjacent beam. Any appearance of not being in alignment is an artifact of the 3D rendering; the math works. However, as already pointed out, the holes are definitely off-grid in the other dimension so I’m not sure how this sort of construction might be useful. I present it anyway just as food for thought.

 

223cos75an

If for some unusual reason you needed to get a very specific offset, you could use this cosine concept to figure out what angle you’d need to get you there. Let’s say you need an 0.6 offset and you’ve decided (usually for construction reasons) you want to go three units along the hypotenuse to get there. You need an angle that has a cosine of 0.2, which, after you’ve gone three units along the angled beam will have moved you 0.6 on the rectilinear grid.  You find the angle using arccos; that angle would be 78.463 and you could build it using (per the table or the program) 5-6-7.

Admittedly, it’s going to be a very unusual set of circumstances that makes you want special offsets — probably involving integrating with other non-Lego parts, or desparately trying to make a non-standard trapezoidal construction work out. Regardless, you’ll still have the problem of the other dimension which just won’t be where you want it anyway. In reality you’ll probably just use an axle and one piece slid along the axle (thus taking on a non-grid position) to get there; thus all this math is probably a waste of space.  But maybe it will inspire someone to do something particularly clever one day.

53.130 degrees

We already saw that this angle (more precisely it is 53.130102) appears in the 3-4-5 family of pythagorean triangles and is the angle of one of the standard lego “bent” beams.

Are there any other triples that generate this angle? Yes, there are. First of all, any isoceles triangle constructed using a mirrored pythagorean 3-4-5 (or multiples of this) will have this angle. We already saw that in the 6-5-5 example.

Other combinations (that are not 3-4-5 in disguise) that give a 53.1301 angle are:

a b c Comments
2 6.5 7.5
4 13 15 Just double 2-6.5-7.5
5 8.5 10.5
6.5 7 7.5 Angle A

There are actually quite a few of these; I’ve only listed some above. All of those except the last form the 53.130 angle at B.

Half Unit Construction

There are many ways to generate half-unit offsets with technic; here’s one construction you may find handy when trying to make these triangles:

hb2

That’s probably the best one I’ve found so far. You can build this with the 1×2 bricks with pins, as shown, or the 1×2 technic bricks (with holes) and separate pins.

Here’s another technique that isn’t quite as elegant but might be handy at times:

halfbeam

The yellow beam and the holes the yellow connector (usually red in real life) form a beam of total length 7.5 (the two holes in the connector are at 6.5 and 7.5).

As shown above the half offset connector is held in place by an axle pin and isn’t necessarily completely stable. You can brace it in a variety of ways if necessary:

halfbeam

That’s it for today’s Lego rambling. Happy Building!


The drawings in posting were created with Bricksmith and rendered using LDView all made possible via LDraw

WSOP Update

Been out in Vegas for a week, played three WSOP events: the shootout, the “turbo” (still has 30 minute levels), and a regular NLHE. Ran well; got third on my table at the shootout (which isn’t in the money – only first is), and min-cashed the other two.

Back to Austin for a break; then next up: WSOP Seniors June 19th.

Showing off with shell “nr” (NumerousApp) command

I wrote some scripts demonstrating what you can do with all the bits and pieces I have now for manipulating NumerousApp metrics from python and shell.

In particular, I was interested in finding the maximum value of one of my metrics:3626358291300704487 (this is the actual NumerousApp metric ID)

I have already installed the python numerous client library and the corresponding shell command “nr” that goes with it (see the github page for details). I also already have my NUMEROUSAPIKEY environment variable set and exported. With all that in place I can read the current value of the metric from a shell prompt like this:

% nr 3626358291300704487

I can read the event stream with the “-E” option:

% nr -E 3626358291300704487

Each line of that output is a (somewhat) human-readable display of a value update event on the metric and looks something like this:

4 @ 2015-05-27T20:12:09.375Z by 9310717522265
3 @ 2015-05-27T19:12:09.348Z by 9310717522265 
2 @ 2015-05-27T18:12:09.207Z by 9310717522265 
1 @ 2015-05-27T17:12:09.373Z by 9310717522265 
0 @ 2015-05-27T15:42:11.373Z by 9310717522265 
518 @ 2015-05-27T14:42:09.254Z by 9310717522265 
517 @ 2015-05-27T13:42:09.116Z by 9310717522265 
516 @ 2015-05-27T12:42:09.317Z by 9310717522265 ...

Rather than parse that output I can ask the “nr” command to only print the value field for each of the events:

% nr -E '3626358291300704487[value]'

From there it’s a simple task to write an awk script that will display the maximum found on stdin:

awk 'BEGIN {max=-999999999} {if ($1>max) {max=$1}} END {print max}'

NOTE: In my script the awk command is all on one line. It’s likely showing up in your browser broken into multiple lines; you need to be careful about those line breaks if you are cutting and pasting this example from your browser display.

That script returns the wrong result if all the input values are negative and below the initial value in the BEGIN statement, so you could do it this way if you prefer:

awk 'BEGIN {max="NOTHING"} {if (max=="NOTHING") max = $1; if ($1>max) {max=$1}} END {print max}'

Again be wary of poorly-located line breaks in your browser display if you copy/paste this.

Given those pieces, finding the max value is a simple pipeline:

% nr -E '3626358291300704487[value]' |
awk 'BEGIN {max="NOTHING"} {if (max=="NOTHING") max = $1; if ($1>max) {max=$1}} END {print max}'

Pretty cool, or maybe somewhat demented.

Sometimes you might not have awk (some linux distributions don’t install it by default), so you could also compute the max with a python program. We know python is on the machine or none of this works, so here’s a version using a python program for the max:

MAXPGM="import sys
maxv = None
for x in sys.stdin:
    try:
        xval = int(x)
    except ValueError:
        xval = float(x)
    if maxv is None or xval > maxv:
       maxv = xval

print(maxv)
"

nr -E '3626358291300704487[value]' | python -c "$MAXPGM"

Making this a script with more general options is left as an exercise for the reader.

Of course if we are going  to the trouble of writing a python program we might want to go ahead and write the entire script in python, which might arguably have been simpler. But, this example notwithstanding, it’s still fun to hack around and see how many powerful things you can do with the “nr” command and some shell.

NumerousApp Server API Performance

I added yet another numerous metric, this time tracking the performance of the NumerousApp server itself:  http://n.numerousapp.com/m/1dlt3ykfq5vqs

It’s measured using this python code:

import numerous

nr = numerous.Numerous()
nr.user()
nr.user()

t = nr.statistics['serverResponseTimes']
print (int(t*10000)/10.0)"

 which is using my NumerousApp Python library (“pip install numerous”).

I just make two user() API calls (discarding the returned info), then dig into the statistics array provided in the object to get the most recent server response time (measured as “on-the-wire” time). The reason for doing two calls is connection overhead; the first call will be significantly slower because it has to perform a TCP connect and an initial SSL setup; the second call reuses the connection (HTTP keep-alive) and is much faster. The numbers are typically around 300msec for the first API call and 60-70msec for subsequent calls (also varies substantially depending on the particular API).

The single response time in ‘statistics’ is the time from the most recent (i.e., second) nr.user() call. The int and 10000/10.0 hack is just to convert the fractional seconds in milliseconds down to tenths (truncated, not rounded … sue me).

NumerousApp libraries updated

Newest versions of my NumerousApp API bindings for python and ruby are released. Now includes support for the new fine-grained permissions server APIs.

PYTHON details:

RUBY details:

NumerousApp overview: www.numerousapp.com

API: http://docs.numerous.apiary.io/

Friday the 13th and NumerousApp

I made a new NumerousApp metric that will tell you when the next Friday the 13th is: http://n.numerousapp.com/m/1w4c4tk4uh29j

Nerd info: I wrote this brute-force python program to find the next Friday the 13th:

from datetime import datetime, date

dt = datetime.now()
while dt.day != 13 or dt.weekday() != 4:
    dt = date.fromordinal(dt.toordinal()+1)

It gets today via  datetime.now()and loops until it is a Friday and a 13th. The weekday() method returns 0 .. 6 with Monday as 0; hence Friday is 4. If “dt” isn’t a Friday the 13th, I just bump it to the next day. The toordinal() method converts a date into a number of days since some arbitrary long-ago time. So I do that, add one, and convert back to a date to get the next day.

I didn’t optimize this algorithm because it just doesn’t matter. I could have added code to compute exactly how many days to add to get to the next 13th and then just test if that is a Friday. Even more generally we could write an algorithm that would directly compute when the next Friday the 13th is (has to take month lengths and leap years into account).

But: We know that at most we’ll have to iterate no more than a few hundred times because every year has at least one Friday the 13th (proving this is left as an exercise for the reader). Speed just doesn’t matter here at all and this works and it is simple.

Once a night I run the above code and use my python NumerousApp API class to update the metric. This too could have been optimized; there’s no reason to run the code at all except on a 13th (indeed, except on a Friday the 13th) but it was just easier to stick it into my nightly updates I do for my other metrics.

Newest versions of NumerousApp API class libraries

As I wrote earlier, I have created Python and Ruby class libraries for the NumerousApp APIs. I’ve recently made a bunch of updates; the newest versions are:

And, as always, github repos: https://github.com/outofmbufs/

Ignore / Enjoy.