0

I am sorry if this is a duplicate question but how would I draw an irregular hendecagon using asymptote? I am new to it and I know how to draw a regular one but not an irregular one.

[asy]
size(9cm);
pair cis(real magni, real argu) { return (magni*cos(argu*pi/180),magni*sin(argu*pi/180)); }

for(int b=1; b<2; b+=1){
for(int a=6; a<7; a+=1){
int n=a+5*b;
pair ctr=(2.5*a,-2.5*b);
real r=1; pair offs=(0,0);
if(n==3) {r=2/3; offs=(0,-1/3);}
for(int i=1; i<2*n; i+=2){
draw(ctr+cis(r/cos(pi/n),270+(i-2)*180/n)+offs---ctr+cis(r/cos(pi/n),270+i*180/n)+offs,blue);
};
};
};
[/asy]

That is my code for a regular hendecagon, but I don't know how to draw an irregular one. Thanks!

  • I am a noob at asymptote ;-; – someone on earth May 5 at 6:56
  • Welcome to TeX.SX! There are many, many irregular hendecagons. Could you be a bit more specific about the one you want to draw? – siracusa May 5 at 6:59
  • Just an irregular one really. It doesn't need anything special. But I would like to know an asymptote trick for drawing irregular polygons(if there is one)! – someone on earth May 5 at 7:01
  • I mean I need a convex one!!! – someone on earth May 5 at 7:13
1

A related question could be How to draw random simple closed smooth curves but with the same perimeter?

With asymptote and the hull_pi.asy package it is easy to have random points and to create the associated convex polygon. You can find hull_pi.asy (not official package) at the following address https://github.com/pivaldi/asymptote-packages/blob/master/hull_pi.asy

Please find a possible solution

    import hull_pi;
    size(10cm);
    // to have a different picture at each launch
    srand(seconds());

    pair[] cloud;
    int nbpt=11;

    path poly_point(pair [] a)
    {
    guide g;
    for (int i; i<size(a);++i)
    g=g--a[i];
    return g--cycle;
    }

    // Generate a first set of random points.
    for (int i=0; i < nbpt; ++i)
      cloud.push((10*unitrand(),10*unitrand()));

    int l=size(hull(cloud));
    while (l<11)
    {
    cloud.push((10*unitrand(),10*unitrand()));
    pair[] phull=hull(cloud);
    l=size(phull);
    }

    pair[] phull=hull(cloud);
    draw(poly_point(phull),1bp+blue);
    dot(phull,red);

and the result

enter image description here

  • thank you!!!!!! – someone on earth May 8 at 19:53
  • @someoneonearth please do not forget to close the subject if it is ok – O.G. May 9 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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