Tuesday, December 4, 2012

Sierpinski Triangle Using Inequalities

(Sierpinski triangle with hearts)


Example 1:
(iterations: 6)

(GIF animation)

gnuplot script 1:

triangle(x,y) = sqrt(3)*abs(x) - 1.5 + abs(sqrt(3)*abs(x) + 2*y - 0.5)
S0(x,y) = sqrt(3)*abs(x) - 0.75 + abs(sqrt(3)*abs(x) - 2*y - 0.25)
S1(x,y) = S0(2*x, 2*y-1) * S0(2*abs(x)-0.5*sqrt(3), 2*y+0.5)
S2(x,y) = S1(2*x, 2*y-1) * S1(2*abs(x)-0.5*sqrt(3), 2*y+0.5)
S3(x,y) = S2(2*x, 2*y-1) * S2(2*abs(x)-0.5*sqrt(3), 2*y+0.5)
S4(x,y) = S3(2*x, 2*y-1) * S3(2*abs(x)-0.5*sqrt(3), 2*y+0.5)
S5(x,y) = S4(2*x, 2*y-1) * S4(2*abs(x)-0.5*sqrt(3), 2*y+0.5)
fun(x,y) = triangle(x,y)>0 || S0(x,y)<0 || S1(x,y)<0 || S2(x,y)<0 || \
               S3(x,y)<0 || S4(x,y)<0 || S5(x,y)<0 ? 0:1
set xrange [-0.5*sqrt(3):0.5*sqrt(3)]
set yrange [-0.5:1]
set pm3d map
unset colorbox
set palette model RGB defined (0 'white', 1 'red')
set size ratio -1
set samples 640
set isosamples 640
unset key
unset xtics
unset ytics
unset border
splot fun(x,y)



Example 2:
(iterations: 6)

(GIF animation)

gnuplot script 2:

S0(x,y) = sqrt(3)*abs(x) - 0.75 + abs(sqrt(3)*abs(x) - 2*y - 0.25)
S1(x,y) = S0(2*x, 2*y - 1) * S0(2*abs(x) - 0.5*sqrt(3), 2*y + 0.5)
S2(x,y) = S1(2*x, 2*y - 1) * S1(2*abs(x) - 0.5*sqrt(3), 2*y + 0.5)
S3(x,y) = S2(2*x, 2*y - 1) * S2(2*abs(x) - 0.5*sqrt(3), 2*y + 0.5)
S4(x,y) = S3(2*x, 2*y - 1) * S3(2*abs(x) - 0.5*sqrt(3), 2*y + 0.5)
S5(x,y) = S4(2*x, 2*y - 1) * S4(2*abs(x) - 0.5*sqrt(3), 2*y + 0.5)
fun(x,y) = (S0(x,y)<0 || S2(x,y)<0 || S4(x,y)<0) ? 2 : \
               ( (S1(x,y)<0 || S3(x,y)<0 || S5(x,y)<0) ? 1 : 0 )
set xrange [-0.5*sqrt(3):0.5*sqrt(3)]
set yrange [-0.5:1]
set pm3d map
unset colorbox
set palette model RGB defined (0 'white', 1 'green', 2 'magenta')
set size ratio -1
set samples 640
set isosamples 640
unset key
unset xtics
unset ytics
unset border
splot fun(x,y)


Graph examples:




( Mathematical softwares used: Graph, gnuplot )

1 comment:

  1. Bài viết rất tuyệt vời, tôi rất thích các thông tin bạn cung cấp, mời các bạn xem các thông tin rất hữu ích để chăm sóc sức khỏe >>> Tìm hiểu các cách trị sâu răng hiệu quả ?

    ReplyDelete