1

In order to pimp a little bit all sets representations in my documents I have been searching for how I could generate patatoid and found this document. However I am not really sure how it works and how it is possible to implement it.

Can someone explain this algorithm and outline the implementation in metapost (with lua(la)tex)?

Ingmar
  • 6,690
  • 5
  • 26
  • 47
cigales
  • 13

1 Answers1

1

I think this question differs from the one linked in a comment both because it is asked for a specific sort of path (the patatoid) and it is explicitly asked for a metapost solution (which does not exist in the linked question).

I interpret the algorithm like this (you can uncomment :

\starttext
\startMPpage[offset=1dk]

vardef patatoid(expr w, h) = hide( numeric maxi,maxd ; maxd := 0 ; numeric dist[] ; pair tmpp[] ; path sq, p ; sq := unitsquare xyscaled (w,h) ; for i = 0 upto 3: tmpp[i] := point (i + uniformdeviate(1)) of sq ; endfor ; tmpp[4] := tmpp[0] ; for i= 0 upto 3 : dist[i] := abs(tmpp[i+1] - tmpp[i]) ; if (dist[i] > maxd) : maxd := dist[i] ; maxi := i ; fi ; endfor ; % draw sq ; % draw tmpp[0]--tmpp[1]--tmpp[2]--tmpp[3]--cycle ; % drawpoints tmpp[0]--tmpp[1]--tmpp[2]--tmpp[3]--cycle withpen pencircle scaled 4 ; p := for i = 0 upto maxi : tmpp[i] .. endfor (uniformdeviate(1))[tmpp[maxi],tmpp[maxi+1]] for i = maxi + 1 upto 3: .. tmpp[i] endfor .. cycle ; % drawpoints p withcolor darkred ; ) p enddef ;

draw patatoid(100,75) withpen pencircle scaled 1 ;

\stopMPpage \stoptext

In the image below I have uncommented the commented lines, showing the rectangle and the points.

a patatoid

The file above is complete if you compile with context. If you are using metapost in some other environment, you should use the part between \startMPpage and \stopMPpage.

mickep
  • 8,685