4

I have the following code:

unitsize(1cm);
path c = circle( (0,0), 1 );
path p(int sides) {return polygon(sides);}

int sides = 3;

for(sides; sides <= 8; ++sides){
    path pol = shift( (2.2sides,0) )*p(sides);
    path cir = shift(2.2sides,0)*c;
    pair vert[] = intersectionpoints( pol , cir );
    draw(pol);
    draw(cir);
    for(int k = 0; k <= vert.length-1; ++k){
        dot(vert[k], L = string(k), fontsize(8pt) );
    }
}

path icos = shift( 2.2(sides) )*polygon(20);
path cir = shift( 2.2(sides) )*unitcircle;
pair vert[] = intersectionpoints( icos, cir );
for(int k = 0; k <= vert.length-1; ++k){
    dot(vert[k]);
}
draw(icos);
draw(cir);

This produces the attached picture; notice that for an odd number of sides, it only computes one intersection point. What I want is to draw the intersection points of a polygon with its circumcircle; note that for the last one, the icosahedron, I used unitcircle instead of circle, just to be sure I got the same result.

My Asymptote version is 2.65, and my Ghostscript version is 9.52; both packaged in the Debian TeXLive 2019 distribution.

How can I get all the intersection points of a regular polygon with its circumcircle? Thanks in advance!

enter image description here

4

Upon reading the documentation I found the routine Circle, of the module graph, with which "a true circle can be produced" (page 31). Using this solves the problem.

settings.outformat="pdf";
unitsize(1cm);
import graph;

path c = Circle( (0,0), 1 );
path p(int sides) {return polygon(sides);}

int sides = 3;

for(sides; sides <= 8; ++sides){
    path pol = shift( (2.2sides,0) )*p(sides);
    path cir = shift(2.2sides,0)*c;
    pair vert[] = intersectionpoints( pol , cir );
    draw(pol);
    draw(cir);
    for(int k = 0; k <= vert.length-1; ++k){
        dot(vert[k], L = string(k), fontsize(8pt) );
    }
}

path icos = shift( 2.2(sides) )*polygon(20);
path cir = shift( 2.2(sides) )*c;
pair vert[] = intersectionpoints( icos, cir );
for(int k = 0; k <= vert.length-1; ++k){
    dot(vert[k], L=string(k), fontsize(4pt));
}
draw(icos);
draw(cir);

path Ellipse(pair centre = (0,0), real xradius, real yradius){
    return shift( ( centre ) )*scale( xradius, yradius )*Circle( (0,0), 1);
}

path elip = shift( 2.2(sides+1) )*Ellipse( (0,0), 1.1, 0.8 );
path cir1 = shift( 2.2(sides+1) )*c;
draw(elip);
draw(cir1);
pair verts[] = intersectionpoints( elip, cir1 );
for(int k = 0; k <= verts.length-1;++k){
    dot(verts[k], L=string(k), fontsize(4pt));
}

enter image description here

9
  • Very useful question and answer, +1 to both.
    – user194703
    Apr 29 '20 at 20:46
  • 1
    No. But from your answer I take that the unreal circle is just a collection of Bezier curves which do not precisely match an exact circle, and thus the intersections are not found.
    – user194703
    Apr 29 '20 at 22:56
  • 1
    Apparently so: on page 12 of the documentation you can read the definition path unitcircle=E..N..W..S..cycle;; it says it is accurate within 0.06%. Apr 29 '20 at 23:14
  • 1
    The intersection points are the vertices of the polygon. Even with Circle function such a behavior (missing intersection points) or having two points may happen depending on the numerical precision and the points which define the circle. Similar situations may happen with two tangent paths. It is due to the numerical method and/or the machine precision.
    – O.G.
    Apr 30 '20 at 12:37
  • 1
    You can also ask to have a precision bigger than the precision machine by intersectionpoints( pol , cir,0.001 ); (try 0.00001). It illustrates the problem of determining points with approximations.
    – O.G.
    Apr 30 '20 at 12:45

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.