The Reuleaux triangle is the shape formed by the intersection of three circles, with each circle passing through the others' centers. Regardless of rotation, a Reuleaux triangle's width will always equal the radius of the circles:

From Wolfram MathWorld

Image: Wolfram MathWorld

Write a program that takes a width r as input and displays a Reuleaux triangle of that width (in pixels).

You must display the shape in isolation, i.e. solid-filled, un-stroked, and over a solid-filled background.

- Shortest program in bytes wins.

  • 1
    \$\begingroup\$ Should the radius r be in pixels or just some scaling factor? \$\endgroup\$
    – Karl Napf
    Commented Jun 13, 2017 at 3:42
  • \$\begingroup\$ @Karl Napf Pixels. \$\endgroup\$
    – darrylyeo
    Commented Jun 13, 2017 at 4:04
  • \$\begingroup\$ Can we output anything to STDOUT, as long as we draw the Reuleaux triangle properly? \$\endgroup\$ Commented Jun 14, 2017 at 16:14
  • \$\begingroup\$ @EriktheOutgolfer That is fine. \$\endgroup\$
    – darrylyeo
    Commented Jun 14, 2017 at 23:24

20 Answers 20


JavaScript + HTML, 164 158 + 13 = 171 bytes

<canvas id=C>

I don't know why I enjoy answering these mathy drawing challenges with <canvas> so much...


Love2D, 320 bytes.

j=math.rad(60)i="increment"m=math s=m.sin C=m.cos g=love.graphics f="fill"S=g.stencil function love.draw()r=arg[2]c=function(x,y)return function()g.circle(f,x,y,r,r*4)end end X=r/2 Y=0 S(c(X,Y),i,1)S(c(X+C(j)*r,Y+s(j)*r),i,1,true)S(c(X-C(j)*r,Y+s(j)*r),i,1,true)g.setStencilTest("greater",2)g.rectangle(f,0,0,2*r,2*r)end

Probably not the optimal solution, it uses Love2D's stencils, setting up the 3 circles, and filling in over where they intersect.

Call via the command line, like love tri.love 256

Example Output

  • 5
    \$\begingroup\$ It's quite lovely \$\endgroup\$
    – ATaco
    Commented Jun 13, 2017 at 7:23

Python 2, 111 bytes

from turtle import*

example run


Mathematica 101 100 98 Bytes

Taking a different approach than @MichaelSeifert, and probably interpreting this a little more literally with regard to the pixel clause:


Usage Example:


10 pixels 10 pixel image

50 pixels 50 pixel image

100 pixels 100 pixel image

Saved a byte thanks to @MartinEnder (infix notation) and another 2 bytes by defining d.


PostScript, 96 86 85 75 73 72 bytes

dup(^@^^Z<^@Z<){sin mul exch dup}forall
0 1 2{newpath 369 arc clip}for fill

Takes the input as a value on the stack. ^^ and ^@ represent literal control characters. (^@^^Z<^@Z<) is the string of characters with code points 0, 30, 90, 60, 0, 90, and 60, respectively. Those are then interpreted as angles in degrees, because obviously that’s what code points are for.

Saved 10 bytes because closepath isn’t needed (both clip and fill implicitly close the path).

Saved 1 byte by using repeat instead of defining a function.

Saved 10 bytes by switching to a completely different approach.

Saved 2 bytes by doing tricks with the stack.

Saved 1 byte by using 0 1 2{}for instead of 3{}repeat.


PHP+SVG, 165 bytes

<?$h=3/8*$w=2*$d=2*$r=$_GET[0];$q=$r+sqrt($r**2-($r/2)**2);echo"<svg width=$w height=$w><path d='M$r,$r A$r,$r 0 0 1 $d,$r A$r,$r 0 0 1 $h,$q A$r,$r 0 0 1 $r,$r'/>";

Example Output for Input 128

<svg width=512 height=512><path d='M128,128 A128,128 0 0 1 256,128 A128,128 0 0 1 192,238.85125168441 A128,128 0 0 1 128,128'/>


TeX/TikZ, 128 121 112 bytes

\input tikz\footline{}\tikz\draw[draw=none,fill=red](0,1)\foreach~ in{1,2,3}{[rotate=~*120]arc(0:60:\r pt)};\bye

The code is based on this answer at TeX.se.

TeX is vector-based, so doesn't do pixels. The radius is a float with a maximum of about 15 before it hits the edge of the page. It's also not really built for commandline input, so need to be run as

pdftex  "\def\r{2} \input rt.tex"

where the code above is saved in rt.tex

  • \$\begingroup\$ A few tips to make this shorter: you don't need any of the newlines; you don't need .tex; \footline{} is just as good as \nopagenumbers; use ~ as a variable name instead of \i. To satisfy the “pixel” requirement, you could use \r sp; 1sp is the sort-of equivalent to a pixel for TeX since it's the finest location TeX can manage (I don't know if it applies to tikz though). \$\endgroup\$ Commented Jun 14, 2017 at 17:03
  • \$\begingroup\$ @Gilles I can't get anything with sp but I think pt is a good idea. All your other ideas worked (some hadn't seemed to in my tests). Thank you \$\endgroup\$
    – Chris H
    Commented Jun 16, 2017 at 15:16
  • \$\begingroup\$ You can remove the space after ~ to save one more byte. \input tikz\footline{}\tikz\draw[draw=none,fill=red](0,1)\foreach~in{1,2,3}{[rotate=~*120]arc(0:60:\r sp)};\bye works for me. Try pdftex "\def\r{2000000} \input rt.tex" — at 2sp finding the shape visually would be difficult given how small it is. \$\endgroup\$ Commented Jun 16, 2017 at 18:07
  • \$\begingroup\$ @Gilles I must admit I only went up to 20000 sp. \$\endgroup\$
    – Chris H
    Commented Jun 16, 2017 at 18:23
  • 1
    \$\begingroup\$ 1pt = 65536sp so 20000sp is still tiny. \$\endgroup\$ Commented Jun 16, 2017 at 18:46

Mathematica, 134 131 bytes

N.B. This solution is no longer valid, as the question was later edited to require r to be measured in pixels. Thanks to Martin Ender for helping me shave off a few bytes in the comments.

r=Input[];RegionPlot[And@@((Abs[y+I x-#]^2<3r^2)&/@Table[Exp[2n I/3Pi]r,{n,3}]),{x,-1,1},{y,-1,1},Frame->False,BoundaryStyle->None]

enter image description here

The input value must be scaled between 0 and 1 for this code to work. Note that almost a quarter of this code is required to display the shape "in isolation", as this is not Mathematica's default.

  • 3
    \$\begingroup\$ Welcome to PPCG! r Exp[2 I Pi n/3] can be Exp[2I n/3Pi]r to save some spaces. And it's generally shorter to write an unnamed function, i.e. drop the r=Input[];, replace r with # and append a &. \$\endgroup\$ Commented Jun 13, 2017 at 6:01
  • \$\begingroup\$ I think the input has to be pixels, not a scaling factor. \$\endgroup\$ Commented Jun 13, 2017 at 16:50
  • 1
    \$\begingroup\$ @pycoder: Yes, that constraint was edited in after I posted my solution. \$\endgroup\$ Commented Jun 13, 2017 at 17:06

BBC BASIC, 58 bytes


Download interpreter at http://www.bbcbasic.co.uk/bbcwin/download.html


INPUTr                       :REM input a radius
LINEr,r,r,r                  :REM draw a line of length 0 from r,r to r,r to establish a cursor history away from the corner of the screen
FORi=0 TO 9 STEP PI/1.5      :REM in steps of 120 degrees (going round and round the three sides of an equilateral triangle)
  PLOT177,r*COS(i),r*SIN(i)  :REM move relative by r*COS(i),r*SIN(i) and draw a sector with arc between new and last graphics cursor positions,
NEXT                         :REM with the centre of the arc at the penultimate graphics cursor position.
  • \$\begingroup\$ Wow, that's practially a built-in! \$\endgroup\$
    – Neil
    Commented Jun 14, 2017 at 8:51

GLSL, 298 229 characters

precision lowp float;
uniform vec2 resolution;float r=100.;void main(){vec2 p=gl_FragCoord.xy-resolution.xy/2.;float h=sqrt(3.)/4.*r;gl_FragColor=vec4(length(p+vec2(r/2.,h))<r&&length(p+vec2(-r/2.,h))<r&&length(p-vec2(0.,h))<r);}

Try it here


  • Radius can be set by changing r variable
  • Triangle width is in pixels as requested (you have to make zoom is set to 1x in GLSL sandbox).
  • \$\begingroup\$ Does GLSL have a standard input method you could use? \$\endgroup\$
    – darrylyeo
    Commented Jun 13, 2017 at 16:21
  • \$\begingroup\$ In glslsandbox, it is possible to get mouse cursor position. This could be used to control triangle radius (eg : radius would be mouse distance from center). \$\endgroup\$
    – tigrou
    Commented Jun 14, 2017 at 13:03

Java + Processing, 95 bytes


Takes input as variable r, outputs a Reuleaux triangle at \$(r,r)\$, given an adequately sized canvas.


As a function with size call, 124 bytes

void a(int r){size(r*2,r*2);noStroke();arc(r,r,r,r,0,PI/3);arc(r+r/2,r,r,r,2*PI/3,PI);arc(r+r/4,r+r/2.3,r,r,4*PI/3,5*PI/3);}



enter image description here


enter image description here


enter image description here


JavaScript (ES6) + HTML, 196 + 13 = 209 bytes

Uses a path-based approach instead of a pixel-filling approach.


<canvas id=c>




<canvas id=c>


Logo, 53 bytes

to t :r filled 0[repeat 3[arc 60 :r fd :r rt 120]]end

uses the filled command to fill the shape in colour 0 (black.) The code in the outer square brackets is executed without any line being drawn, but Logo keeps track of the turtle movements and fills in the shape once the bracket is exited.

Logo, 64 61 bytes

to t :r repeat 3[pd arc 60 :r pu fd :r rt 120]fd 9 fill end

Pen Down, draw 60 degree arc with turtle at the centre, Pen Up, move pen to start of arc, turn 120 deg.

Repeat 3 times, then move inside the shape and fill it.

Try at http://turtleacademy.com/playground/en

Call like cs ht t 100 (clear screen, hide turtle, t with r=100.)


JavaScript (ES6) + SVG (HTML5), 28 + 102 = 130 bytes

<input type=number value=82 oninput=f(this.value)><br>
<svg id=s width=82 viewbox=0,0,82,82><path d=M0,71a82,82,0,0,0,82,0A82,82,0,0,0,41,0A82,82,0,0,0,0,71>

Byte count excludes code needed for convenient user input of desired size.

  • \$\begingroup\$ Clever! n=>s.style.width=n would work also. \$\endgroup\$
    – darrylyeo
    Commented Jun 14, 2017 at 1:02
  • \$\begingroup\$ I can't seem to figure out how you came to 112 bytes. \$\endgroup\$
    – darrylyeo
    Commented Jun 14, 2017 at 1:09
  • \$\begingroup\$ @darrylyeo That suggestion didn't work for me, sorry, but I agree about the byte count, I can't figure out how I came to it either. \$\endgroup\$
    – Neil
    Commented Jun 14, 2017 at 1:18
  • \$\begingroup\$ Hmm, probably only works in Chrome. \$\endgroup\$
    – darrylyeo
    Commented Jun 14, 2017 at 1:20

MATL, 35 bytes


This produces a file called image.png. For input r, the size of the image is 2*r+1, and the width of the triangle is r as required.

Try it at MATL Online! The online interpreter automatically opens the created file and displays the image with arbitrary scaling; click on it to obtain the actual-size version.

Alternatively, here are two example outputs from the offline compiler running on Matlab, with inputs 50 and 100. The last part of the code 0YG has been replaced by IYG so that the figure is directly displayed (with the right size) instead of written to a file.

enter image description here


9B      % Push 9 in binary: [1 0 0 1] with logical values
o       % Convert to double
&ZQ     % Roots of polynomial with coefficients [1 0 0 1], as a 3×1 column vector
*       % Multiply by implicit input r
3X^/    % Divide by sqrt(3). This gives a 3×1 vector with the circle centers
G_G&:   % Push row vector [-r -r+1 ... r-1 r], with size 1×(2*r+1)
t!J*    % Duplicate, transpose, multiply by 1j
+       % Add with broadcast. This gives a (2*r+1)×(2*r+1) 2D-array of complex
        % numbers, which defines the pixel grid
8L      % Push [3 1 2]
&!      % Permute dimensions as indicated. This gives a 1×(2*r+1)×(2*r+1) 3D-array
-|      % Subtract with broadcast. Absolute value. This gives a 3×(2*r+1)×(2*r+1)
        % 3D-array with the distance from each circle center to each grid point
G<      % Less than r? Gives a 3×(2*r+1)×(2*r+1) 3D-array containing true or false
A       % All: this gives a 1×(2*r+1)×(2*r+1) array containing true for
        % columns of the original 3D-array that contained all true values
&e      % Squeeze the first singleton dimension to give a (2*r+1)×(2*r+1) 2D-array
0YG     % Save as image file with default file name

MetaPost (242 226 Bytes)

 path p[];
 p[1]:=len * dir -30 {dir 90} .. len * dir  90;
 p[2]:=p[1] rotated 120;
 p[3]:=p[1] rotated 240;
 fill p[1] -- p[2] -- p[3] -- cycle;

It may be possible to reduce this somewhat, I'm new to metapost.

  • \$\begingroup\$ I was a bit lazy and used the text editors byte count. I didn't know you could remove the colons, Thanks. I literally have an hour of MetaPost under the belt now ^_^ \$\endgroup\$
    – Carel
    Commented Jun 14, 2017 at 1:24
  • 1
    \$\begingroup\$ I still count 223, not 226. Also, can you remove the spaces in len * dir and the dot at the end? \$\endgroup\$
    – Riker
    Commented Jun 14, 2017 at 2:24

05AB1E, 66 bytes

lt(60’Ð’€š éà £Ø*
„ˆ 1:ht()’.e

Can't use TIO, since it opens a window and draws the Reuleaux triangle there.

Asks for input, and then opens up a Python turtle window drawing the triangle.

Jonathan Allan's answer gave me the inspiration to do this, although I altered his code a bit.

Essentially, this is a combination of 05AB1E's compressing capabilities and Python's ease of turtle graphics.


k, 141 100 98 bytes

`0:(,"P1")," "/'$(,l,l),&/{(s'n+x)</:(s r)-s'y+n:r-!l}./:r*%(0 0;4 0;1 3)%4

Input is taken from stdin, output is stderr (or stdin depending on the interpreter) in pgm format. For example:

Example of the program working.


s:*/2#               /set s to a squaring function
r:.:0:`              /get user input, set to r
l:2*                 /width/height is 2 times r
r*%(0 0;4 0;1 3)%4   /the coordinates of circle centers
{ }./:               /for each coordinate pair (x, y) get a circle
                     /function to get a circle:
n:r-!l               /  set n to {r, r-1, ..., -(r-1)}
(s'n+x)</:(s r)-s'y+ /  use b^2<r^2-a^2 on all points to get a circle
                     /  where x and y shift the circle right and down
&/                   /get intersections of circles (fold binary and)
(,l,l),              /prepend height and width for PGM format
" "/'$               /convert to string, add spaces
(,"P1"),             /prepend PGM header
`0:                  /output to stderr
\\                   /exit

OpenSCAD, 91 bytes

module t(r){intersection_for(t=[0,120,240]){rotate(t)translate([r/sqrt(3),0,0])circle(r);}}

I'm not sure how kosher this is, as pixels aren't really a well-defined unit in any mesh grid formats that I know of. In stead, the module t draws a reuleaux triangle of given radius r in whatever native units are in use.

Sample preview output for t(100): t(100)


SmileBASIC, 87 86 85 83 82 81 79 78 77 76 75 bytes

A=X*240GCIRCLE R*X,Y+2,R,A-60,A



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.