# Draw Sri Yantra

Draw Sri Yantra.

## How to:

There are different ways to draw it. All include many steps. If you think you can draw it without following the linked steps scroll below for the elements you must have in your drawing.

Complete steps can be found here:

http://www.saralhindi.com/Shri_Yantra/makingsky14steps_eng.htm

(I didn't copied them here because it would become a very long question, here is archieve.org mirror in case the first link ever goes down)

The final picture should look like the picture below:

## Must have:

Basically any method of drawing of your choosing would be a valid answer providing that you keep the most important elements

1. The number of triangles should the same number as in the above picture (43 smaller triangles resulted from the interlacing of the bigger 9 triangles)

2. This triple intersections are respected:

1. The tips of the upward triangles touch the bases of the 4 downward triangles and the tips of downward triangles should touch the bases of the 3 upward triangles as shown in the figure bellow.

2. The inner circle (bindu) is concentric with the outer circle.

3. The tips (vertices) of the bigger triangles should touch the outer circle:

4. The final image should have all the elements and should generally look like:

5. Color should be roughly the same as the above image for every element (including petals).

6. The shape of the petals should preferably look roughly like in the image bellow, but can also be just semicircles or simple arc section of circle:

7. There are no strict proportion restrictions to the circles or the size of the gates, but the most outer circle should have the diameter not less than 90% of the side of the outer square, the other elements would be respectively arranged relative to this proportions.

## Programming languages and results

There are no restriction to the programming language nor the format of the result (it can be either a vector image, bitmap image, canvas etc) provided that the result is relatively clear and discernible (at least 800px X 800px)

Latter edit: There is no perfect method of drawing as this blog so well explores them: http://fotthewuk.livejournal.com/ Taking that into account minor faults will be tolerated.

At this point it as an interesting exercise to learn that it is very probable that there is no perfect solution, much like squaring of the circle.

• I think you'll need to define the colour palette, the relevant length scales of the outer circles and the background and the shape of the petals. – Martin Ender Dec 16 '14 at 14:28
• @MartinBüttner I reedited the question, please tell me if the info is better now. Drawing this Yantra is no easy challenge, and laying the specs is a bit challenging too – Eduard Florinescu Dec 16 '14 at 15:40
• Hi, I know the spec is very tough on this one. But it is required. My recent similar question was also given a hard time because of spec, so its better you come up with one because without that, this is too hard to draw and practically not a real challenge . – Optimizer Dec 16 '14 at 18:13
• This challenge is crazy. – A.L Dec 17 '14 at 2:01
• Thanks, got it figured out already though ;) And damn.. this is hard, Only got the triangles done and my code is huge already. Optimizing it now xD – Teun Pronk Dec 18 '14 at 8:21

# Mathematica - 2836 2536 chars

It was a bit dizzying to figure out the combos of regions that make small triangles available for coloring.

## The Frame

The frame objects are inequalities that describe as regions. E.g. the red and yellow scalloping are two regions of circles.

n1=8;n2=16;
w8=Round[.78 Table[{Cos[2\[Pi] k/n1],Sin[2\[Pi] k/n1]},{k,0,n1-1}],.01];
w16=Round[1 Table[{Cos[2\[Pi] k/n2],Sin[2\[Pi] k/n2]},{k,0,n2-1}],.01];
n=12;y1=.267;
x2=1/Sqrt[2];w=1.8;v=1.85;
pts={{-w,w},{-w/4,w},{-w/4,w+w/8},{-5w/8,w+w/8},{-5w/8,w+5w/24},{5w/8,w+5w/24},{5w/8,w+w/8},{w/4,w+w/8},{w/4,w},
{w,w},{w,w/4},{w+w/8,w/4},{w+w/8,5w/8},{w+5w/24,5w/8},{w+5w/24,-5w/8},{w+w/8,-5w/8},{w+w/8,-w/4},{w,-w/4},
{w,-w},
{w/4,-w},{w/4,-w-w/8},{(5 w)/8,-w-w/8},{(5 w)/8,-w-(5 w)/24},{-((5 w)/8),-w-(5 w)/24},{-((5 w)/8),-w-w/8},{-(w/4),-w-w/8},{-(w/4),-w},{-w,-w},

{-w,-w/4},{-w-w/8,-w/4},{-w-w/8,-5w/8},{-w-5w/24,-5w/8},{-w-5w/24,5w/8},{-w-w/8,5w/8},{-w-w/8,w/4},{-w,w/4}
};

frame=RegionPlot[{
(*MeshRegion[pts2,Polygon[Range[20]]],*) (*orange trim *)
MeshRegion[pts,Polygon[Range[Length[pts]]]], (*green box *)
ImplicitRegion[x^2+y^2<2.8,{x,y}], (*white, largest circle *)
ImplicitRegion[Or@@(((x-#)^2+(y-#2)^2<.1)&@@@w16),{x,y}], (*yellow scallops*)
ImplicitRegion[x^2+y^2<1,{x,y}],(*white circle *)
ImplicitRegion[x^2+y^2<1.4,{x,y}],(*white disk*)
ImplicitRegion[Or@@(((x-#)^2+(y-#2)^2<.15)&@@@w8),{x,y}],(*red scallops*)
ImplicitRegion[x^2+y^2<1,{x,y}] , (*white disk *)
ImplicitRegion[1.8 < x^2+y^2< 2.2,{x,y}] ,(*brown outer rim*)
ImplicitRegion[2.4 < x^2+y^2< 2.8,{x,y}](*yellow outer rim*)},
BoundaryStyle->Directive[Thickness[.005],Black],
AspectRatio->1,
Frame-> False,
PlotStyle->{(*Lighter@Orange,*)
Darker@Green,White,Yellow,White,White,
Red,White,Lighter@Brown,Yellow,Red,
White,White,White,White,White,
White,White,Red,Red,Darker@Blue,
Darker@Blue,Darker@Blue,Darker@Blue,Darker@Blue,Darker@Blue,
Red,Red,Darker@Blue,Red,Yellow,Red}];


Then there is a disk to hide some circles that were used to make the scalloping.

Graphics[{White,Disk[{0,0},.99]}]


## The Innards

Some definitions of vertices and triangles. Each triangle, t1, t2,... is a distinct region. Logical operations (RegionUnion. RegionIntersection, and RegionDifference) on large triangles are used to define smaller, triangular cells as derived regions that can be individually colored.

p1={-Cos[ArcTan[.267]],y1};
p2={Cos[ArcTan[.267]],y1};
p3={-Cos[ArcTan[.267]],-y1};
p4={Cos[ArcTan[.267]],-y1};
p5={-x2,(x2+y1)/2};
p6={x2,(x2+y1)/2};
p7={-x2,-(x2+y1)/2};
p8={x2,-(x2+y1)/2};
p9={0.5,-x2};
p10={-0.5,-x2};
p11={0.5,-x2};
p12={-0.5,-x2};
p13={a=-.34,b=-.12};
p14={-a,b};
p15={0.5,x2};
p16={-0.5,x2};
t1=MeshRegion[{{0,-1},p1,p2},Triangle[{1,2,3}]];
t2=MeshRegion[{{0,1},p3,p4},Triangle[{1,3,2}]];
t3=MeshRegion[{{0,-x2},p5,p6},Triangle[{1,3,2}]];
t4=MeshRegion[{{0,x2},p7,p8},Triangle[{1,3,2}]];
t5=MeshRegion[{{0,+y1},p9,p10},Triangle[{1,3,2}]];
t6=MeshRegion[{{0,p5[[2]]},p13,p14},Triangle[{1,3,2}]];
t7=MeshRegion[{{0,p13[[2]]},p15,p16},Triangle[{1,3,2}]];
t8=MeshRegion[{{0,p7[[2]]},{-.33,p1[[2]]-.12},{.33,p1[[2]]-.12}},Triangle[{1,3,2}]];
t9=MeshRegion[{{0,p3[[2]]},{z=-.23,0.063},{-z,.063}},Triangle[{1,3,2}]];


disk=Graphics[{White,Disk[{0,0},.99]}];

innards=RegionPlot[{
t1,t2,t3,t4,t5,t6,t7,t8,t9,(*White*)
RegionDifference[t1,RegionUnion[t5,t4,t2]],(*Blue*)
RegionDifference[t4,RegionUnion[t1,t3,t5]],(*red*)
RegionDifference[t3,RegionUnion[t7,t4,t2]], (*blue*)
RegionDifference[t2,RegionUnion[t1,t7,t3]], (*blue*)
RegionDifference[t5,t1],   (*blue*)
RegionDifference[t4,RegionUnion[t1,t7]], (*Blue *)
RegionDifference[t7,t2],(*Blue*)
RegionDifference[t3,RegionUnion[t1,t2]],(*Blue *)
RegionDifference[t8,t2],  (* blue *)
RegionDifference[t9,t5],  (* red *)
RegionDifference[t9,t6],  (* red *)
RegionIntersection[t4,RegionDifference[t6,t1]], (*blue*)
RegionIntersection[t6,RegionDifference[t5,t8]],  (* red *)
RegionIntersection[t7,t9], (*yellow*)
RegionDifference[RegionIntersection[t7,t8],t5], (*red *)
RegionDifference[RegionIntersection[t5,t6],RegionUnion[t7,t9]],(*red *)
ImplicitRegion[x^2+y^2<= .001,{x,y}],  (* smallest circle *) (* red *)
RegionDifference[RegionIntersection[t7,t1 ],t6], (*Red*)
RegionDifference[t8,RegionUnion[t5,t6]],
RegionDifference[t6,RegionUnion[t7,t8]],
RegionDifference[RegionIntersection[t2,t5],RegionUnion[t7,t8]],
RegionDifference[RegionIntersection[t7,t3],t4],
RegionDifference[RegionIntersection[t1,t3],RegionUnion[t5,t4]],
RegionDifference[RegionIntersection[t2,t4],RegionUnion[t7,t3]],
RegionDifference[RegionIntersection[t5,t4],t3]},
BoundaryStyle->Directive[Thickness[.005],Black],
AspectRatio->1,
PlotStyle->{
White,White,White,White,White,White,White,White,White,
Blue,Red,Red,Blue,Blue,Blue,Blue,Blue,Blue,
Red,Red,Blue,Red,Yellow,Red,Red,Red,Blue,Blue,Blue,Blue,Red,Red,Red,Red}]


## Putting the parts together

Show[frame,disk,innards,Graphics[{Brown,Thickness[.02],Line[Append[pts,{-w,w}]]}];
Graphics[{RGBColor[0.92,0.8,0.],Thickness[.015],Line[Append[pts,{-w,w}]]}]]


## Golfed

r=ImplicitRegion;m=MeshRegion;t=Triangle;d=RegionDifference;u=RegionUnion;i=RegionIntersection;(*s=ImplicitRegion*)

n1=8;n2=16;w8=.78 Table[{Cos[2\[Pi] k/n1],Sin[2\[Pi] k/n1]},{k,0,n1-1}];
w16=Table[{Cos[2\[Pi] k/n2],Sin[2\[Pi] k/n2]},{k,0,n2-1}];n=12;y1=.267;x2=1/Sqrt[2];w=1.8;v=1.85;
pts={{-w,w},{-w/4,w},{-w/4,w+w/8},{-5w/8,w+w/8},{-5w/8,w+5w/24},{5w/8,w+5w/24},{5w/8,w+w/8},{w/4,w+w/8},{w/4,w},
{w,w},{w,w/4},{w+w/8,w/4},{w+w/8,5w/8},{w+5w/24,5w/8},{w+5w/24,-5w/8},{w+w/8,-5w/8},{w+w/8,-w/4},{w,-w/4},
{w,-w},{w/4,-w},{w/4,-w-w/8},{(5 w)/8,-w-w/8},{(5 w)/8,-w-(5 w)/24},{-((5 w)/8),-w-(5 w)/24},{-((5 w)/8),-w-w/8},{-(w/4),-w-w/8},{-(w/4),-w},{-w,-w},
{-w,-w/4},{-w-w/8,-w/4},{-w-w/8,-5w/8},{-w-5w/24,-5w/8},{-w-5w/24,5w/8},{-w-w/8,5w/8},{-w-w/8,w/4},{-w,w/4}};

frame=RegionPlot[{
m[pts,Polygon[Range[Length[pts]]]],
r[x^2+y^2<2.8,{x,y}],
r[Or@@(((x-#)^2+(y-#2)^2<.1)&@@@w16),{x,y}],
r[x^2+y^2<1,{x,y}],
r[x^2+y^2<1.4,{x,y}],
r[Or@@(((x-#)^2+(y-#2)^2<.15)&@@@w8),{x,y}],
r[x^2+y^2<1,{x,y}] ,
r[1.8 < x^2+y^2< 2.2,{x,y}] ,
r[2.4 < x^2+y^2< 2.8,{x,y}]},
BoundaryStyle->Directive[Thickness[.003],Black],
AspectRatio->1,
Frame-> False,
PlotStyle->{Darker@Green,White,Yellow,White,White,Red,White,Lighter@Brown,Yellow,Red}];

c=Cos[ArcTan[y1]];
p1={-c,y1};
p2={c,y1};
p3={-c,-y1};
p4={c,-y1};
p5={-x2,(x2+y1)/2};
p6={x2,(x2+y1)/2};
p7={-x2,-(x2+y1)/2};
p8={x2,-(x2+y1)/2};
p9={0.5,-x2};
p10={-0.5,-x2};
p11={0.5,-x2};
p12={-0.5,-x2};
p13={a=-.34,b=-.12};
p14={-a,b};
p15={0.5,x2};
p16={-0.5,x2};
t1=m[{{0,-1},p1,p2},t[{1,2,3}]];
t2=m[{{0,1},p3,p4},t[{1,3,2}]];
t3=m[{{0,-x2},p5,p6},t[{1,3,2}]];
t4=m[{{0,x2},p7,p8},t[{1,3,2}]];
t5=m[{{0,+y1},p9,p10},t[{1,3,2}]];
t6=m[{{0,p5[[2]]},p13,p14},t[{1,3,2}]];
t7=m[{{0,p13[[2]]},p15,p16},t[{1,3,2}]];
t8=m[{{0,p7[[2]]},{-.33,p1[[2]]-.12},{.33,p1[[2]]-.12}},t[{1,3,2}]];
t9=m[{{0,p3[[2]]},{z=-.23,0.063},{-z,.063}},t[{1,3,2}]];

innards=RegionPlot[{
d[t1,u[t5,t4,t2]],
d[t4,u[t1,t3,t5]],
d[t3,u[t7,t4,t2]],
d[t2,u[t1,t7,t3]],
d[t5,t1],
d[t4,u[t1,t7]],
d[t7,t2],
d[t3,u[t1,t2]],
d[t8,t2],
d[t9,t5],
d[t9,t6],
i[t4,d[t6,t1]],
i[t6,d[t5,t8]],
i[t7,t9],
d[i[t7,t8],t5],
d[i[t5,t6],u[t7,t9]],
r[x^2+y^2<= .001,{x,y}],
d[i[t7,t1 ],t6],
d[t8,u[t5,t6]],
d[t6,u[t7,t8]],
d[i[t2,t5],u[t7,t8]],
d[i[t7,t3],t4],
d[i[t1,t3],u[t5,t4]],
d[i[t2,t4],u[t7,t3]],
d[i[t5,t4],t3]},
BoundaryStyle->Directive[Thickness[.003],Black],
Frame->False,
PlotStyle->{Blue,Red,Red,Blue,Blue,Blue,Blue,Blue,Blue,
Red,Red,Blue,Red,Yellow,Red,Red,Red,Blue,Blue,Blue,Blue,Red,Red,Red,Red}];

trim=Graphics[{RGBColor[0.92,0.8,0.],Thickness[.01],Line[Append[pts,{-w,w}]]}];
trim2=Graphics[{Brown,Thickness[.02],Line[Append[pts,{-w,w}]]}];
Show[frame,Graphics[{White,Disk[{0,0},.99]}],trim2,trim,innards]

• *innards, and this is completely amazing; have a +1 – Soham Chowdhury Dec 19 '14 at 6:22
• Struggling with the colors here aswell, although the inner circle with triangles is all I have so far. I have some catching up to do ;) – Teun Pronk Dec 19 '14 at 9:51
• Teun Pronk, It helps to use layers for the frame (everything outside the blue triangles). The moon-like petals can be achieved by rendering full circles and overlaying them with a large white disk onto which the central figure is rendered. For me the hardest part is coloring the inner triangular cells. – DavidC Dec 19 '14 at 10:52
• Same, really hard. Trying to work out something with recursion but can't get it to work yet. – Teun Pronk Dec 19 '14 at 11:05
• @DavidCarraher I fixed the coloring part. Want a tip about it? – Teun Pronk Dec 19 '14 at 13:40

# Delphi [Work in progress]

This one is really hard..
So far all I have is the inner circle with the triangles and my code is huge.
Haven't counted the characters yet, I know I can save a lot on whitespaces etc.

### To begin with

I made a class TD T is a default class prefix not mandatory but it makes it easy to see its a class, D stands for Draw.

  TP = TPoint;
TD = class
private
FCv: TCanvas;
FC: TP;
a:array[1..9,0..2]of TP;
FB:TBitmap32;
FWi: integer;
public
constructor Create(AC: TCanvas;CP:TP;W:integer);
procedure tr;
procedure StartDrawing;
procedure ft;
end;
const t=1>0;f=0>1;off=50;ic=500;


I also made a TP type, nope, not since they're my initials but its shorter than TPoint and I figured I would use a lot of points.
property C is the centerpoint of the canvas.
procedures:
StartDrawing (yet to be renamed) fires all the drawing functions for me.
tr makes all triangles in the circle (including the circle itself)
ft will color all triangles.
I also made some constants for true and false, offset and the size of the circle.

### Functions and procedures

Q will return the point where 2 lines cross/intersect.
There are a lot of nested function/procedures. I dont feel like explaining them all but if you wonder what something does you can always ask.

### Complete class

unit Unit3;
interface
Uses
Windows,Sysutils, Classes, DateUtils, Math, Graphics, types,idglobal, gr32, gr32_polygons, GR32_Backends;
type
TP = TPoint;
TD = class
private
FCv: TCanvas;
FC: TP;
a:array[1..9,0..2]of TP;
FB:TBitmap32;
FWi: integer;
public
constructor Create(AC: TCanvas;CP:TP;W:integer);
procedure tr;
procedure StartDrawing;
procedure ft;
const
ic=500;
end;
const t=1>0;f=0>1;off=50;
implementation

function q(A1,A2,B1,B2:TP;out o:int16):TP;
Var
a,b,c:Real;
d,e:TP;
begin
a:=A1.X*A2.Y-A1.Y*A2.X;
b:=B1.X*B2.Y-B1.Y*B2.X;
d:=A1.Subtract(A2);
e:=B1.Subtract(B2);
c:=1/((d.X*e.Y)-(d.Y*e.X));
Result:=TP.Create(Round(((a*e.X)-(d.X*b))*c),Round(((a*e.Y)-(d.Y*b))*c));
o:=Result.Y;
end;
constructor TD.Create(AC: TCanvas; CP:TP;W:integer);
begin
FCv:=AC;
FC:=CP;
FWi:=W;
FB := TBitmap32.Create;
FB.SetSize(W,W);
end;

procedure TD.ft;
var
X,Y:int32;
procedure cl(f,g:int32;e:TColor);
begin
fb.Canvas.Brush.Color:=e;
fb.Canvas.FloodFill(f,g,clBlack32, fsBorder);
end;
function it(p1,p2: int32):int32;
var i,r:int32;
rgn:HRGN;
begin
r:=0;
if fb.Pixel[x,y]<>clPurple32 then
exit(50);
for I := 1 to 9 do
begin
rgn:=CreatePolygonRgn(a[i],3,WINDING);
if PtInRegion(rgn,p1,p2) then
r:=r+1;
end;
it:=r;
end;
begin
Y:=c.Y;
fb.Canvas.Brush.Color := clHighlight;
fb.Canvas.FloodFill(1,1,clBlack32, fsBorder);
X := c.X;
cl(c.x-1,51,clWhite);
for Y := 0 to fwi-1 do
for X := 0 to fwi-1 do
case it(x,y) of
0,2,4,6,8:cl(x,y,clwhite);
1,5:cl(x,y,clNavy);
3,7:cl(x,y,clred);
end;
end;
procedure TD.StartDrawing;
begin
with fcv do
begin
Brush.Style := bsSolid;
Brush.Color := clBtnFace;
Ellipse(off,off,ic+off,ic+off);
Brush.Style:=bsClear;
tr;
ft;
CopyRect(ClipRect, FB.Canvas, FB.ClipRect);
Brush.Color := clRed;
Ellipse(c.X-10,c.Y-5,c.X+10,c.Y+15);
end;
end;
procedure TD.tr;
const
L=250;
var
p1,w,v:tp;
i:int16;
r:TRect;
function e(n:int16;b:boolean=f):TP;
var r:single;
begin
Result := tp.Create(C.X +Round(L*Cos(r)),C.Y+Round(L*Sin(r)));
end;
function CS(Y:integer; L:boolean=t): tp;
var
I: integer;
begin
with FCv do
if L then
begin
for I := 0+off to 499+off do
if Pixels[I,Y]=0 then
exit(TP.Create(I+1,Y));
end
else
for i := 499+off downto 0+off do
if Pixels[I,Y]=0 then
exit(TP.Create(I-1,Y));
end;
procedure d(n,x,y:int16;b,c:TP);
begin
a[n][0]:=TP.Create(x,y);
a[n][1]:=b;
a[n][2]:=c;
end;
function Int(a,b,c,d,s1,s2:tp;h:int32):tp;
var
f,ww:tp;
e:extended;
begin
f:=q(a,b,c,d,i);
e:=ArcTan2(f.Y-h,f.X-c.X);
ww:=tp.Create(C.X +ceil(500*Cos(e)),r.Bottom+ceil(500*Sin(e)));
s2.Y:=ww.Y;
Result:=q(f,ww,s1,s2,i);
end;
begin
r:=trect.Create(e(225,t),e(45,t));
q(e(12),e(9),e(10),e(6),i);
d(1,C.X,off+ic-1,CS(i),CS(i,f));
q(e(12),e(8),e(9),e(6),i);
d(2,C.X,off+1,CS(i),CS(i,f));
w:=int(a[1][1],a[1][2],a[2][0],a[2][1],r.TopLeft,tp.Create(r.Left,0), r.Bottom);
d(3,c.X,r.Bottom,w,tp.Create(r.Right,w.Y));
w.Y:=r.Bottom-(w.Y-r.Top);
d(4,c.X,r.Top,w,tp.Create(r.Right,w.Y));
w:=int(a[1][0],a[1][1],a[4][1],a[4][2],tp.Create(r.Left,0),tp.Create(r.Bottom,0),r.Top);
w.Y:=r.BottomRight.Y;
v:=tp.Create(w);
v.X := c.X+(c.X-w.X);
d(5,c.X,a[1][1].Y,w,v);
p1:=q(a[3][0],a[3][1],q(a[2][0],a[2][2],a[3][0],a[3][2],i),q(a[1][0],a[1][1],a[4][0],a[4][1],i),i);
d(6,c.X,a[3][1].Y,p1,tp.Create(c.X+(c.X-p1.X),p1.Y));
d(7,c.X,p1.Y, tp.Create(a[5][1]),tp.Create(a[5][2]));
a[7][1].Y:=r.Top;
a[7][2].Y:=r.Top;
w:=q(a[6][0],a[6][1],a[7][0],a[7][1],i);
w:=q(w,tp.Create(w.X-20,w.Y),a[4][0],a[4][1],i);
d(8,c.X,a[4][1].Y,w,tp.Create(c.X+(c.X-w.X),w.Y));
w:=q(a[5][0],a[5][1],a[7][0],a[7][1],i);
w:=q(w,tp.Create(w.X-20,w.Y),a[6][0],a[6][1],i);
d(9,c.X,a[2][1].Y,w,tp.Create(c.X+(c.X-w.X),w.Y));
FB.Clear(clPurple32);
FB.PenColor := clBlack32;
fb.Canvas.Brush.Style:=bsClear;
FB.Canvas.Ellipse(off,off,500+off,500+off);
for I := 1 to 9 do
begin
p1:=a[i][0];
w:=a[i][1];
v:=a[i][2];
FB.Line(p1.X,p1.Y,w.X,w.Y, fb.PenColor);
FB.Line(p1.X,p1.Y,v.X,v.Y,fb.PenColor);
FB.Line(v.X,v.Y,w.X,w.Y,fb.PenColor);
end;
FB.Canvas.Brush.Color := clYellow;
FB.Canvas.FloodFill(c.X,c.Y,clBlack32, fsBorder);
end;
end.


Result so far: (Yes I know lines aren't perfect everywhere. Can't find the problem :( )
Dont know why but the triangles dont show their outlines. They do on my saved bmp though.

• Any updates on this? – Taylor Scott Sep 10 '17 at 16:27