Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am supposed to add code that uses a forumla to create a circle from a polygon

ID: 3541117 • Letter: I

Question

I am supposed to add code that uses a forumla to create a circle from a polygon to return a polyline with the minumum number of sides to be within a half pixel of a circle of the given radius. This is written in c++ using open GL



    int nSides = 6;
    nSides = ceil(nSides);
    double dTheta = M_PI / 2; // 90 degrees
    double conversion = PI / 180;

    // drawing an nSides-sided polygon requires nSides + 1 vertices
    int nVertices = nSides + 1;

    Point2 *vertices = new Point2[nVertices];

    for (int iVertex = 0; iVertex < nVertices; iVertex++) {
        double theta = (180 * (nSides - 2))/(2 * nSides) * conversion;
        vertices[iVertex].u.g.x = center.u.g.x + radius * cos(theta);
        vertices[iVertex].u.g.y = center.u.g.y + radius * sin(theta);
    }
    PolyLine *polyLine = new PolyLine(vertices, nVertices, true, shaderProgram);
    delete [] vertices;
    return polyLine;

Explanation / Answer

please see here http://pastebin.com/AJUEaaYP

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote