ThinkGeo.com    |     Documentation    |     Premium Support

Create sectors of a circle

Are there any built-in mapsuite tools for creating sectors of a circle? I’m trying to create shapes to appear like so:

I have a center point, length (which will be the radius of the circle and the length of the two sides), and an angle. This is supposed to represent something like sonar.

Hi Dan,

Sorry we don’t have related API or built-in tool for this requirement.

You should want to calculate this shape by custom algorithm and then draw it on map.

If you found draw arc is not easy, you can try to build a circle, then get the arc line from it.

Regards,

Ethan

Figured it out from an old post I saw somewhere on this forum for anyone trying to do the same thing:

    private MultipolygonShape BuildPiePolygon(PointShape centerPointShape, double radius, double startAngle, double sweepAngle)
    {
        PolygonShape polygonShape = new PolygonShape();
        EllipseShape ellipseShape = new EllipseShape(centerPointShape, radius);

        PointShape pointShape1 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
        pointShape1.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle));
        polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center));
        polygonShape.OuterRing.Vertices.Add(new Vertex(pointShape1));

        if ((sweepAngle > 90) && (sweepAngle <= 180))
        {
            PointShape midPointShape1 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape1.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 90));
            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape1));
        }
        else if ((sweepAngle > 180) && (sweepAngle <= 275))
        {
            PointShape midPointShape1 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape1.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 90));
            PointShape midPointShape2 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape2.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 180));

            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape1));
            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape2));

        }
        else if ((sweepAngle > 275) && (sweepAngle <= 360))
        {
            PointShape midPointShape1 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape1.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 90));
            PointShape midPointShape2 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape2.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 180));
            PointShape midPointShape3 = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
            midPointShape3.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + 275));

            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape1));
            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape2));
            polygonShape.OuterRing.Vertices.Add(new Vertex(midPointShape3));
        }

        PointShape pointShapeSweep = new PointShape(ellipseShape.Center.X, ellipseShape.Center.Y);
        pointShapeSweep.TranslateByDegree(ellipseShape.Width, CorrectAngle(startAngle + sweepAngle));
        polygonShape.OuterRing.Vertices.Add(new Vertex(pointShapeSweep));
        polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center));

        MultipolygonShape intersectionMultiPolygonShape = ellipseShape.GetIntersection(polygonShape);
        return intersectionMultiPolygonShape;
        //return polygonShape; 
    }

    private double CorrectAngle(double angle)
    {
        double correctAngle;
        if (angle > 360)
            correctAngle = angle - 360;
        else
            correctAngle = angle;
        return correctAngle;

    }
}

Hi Dan,

That’s a good news there is an algorithm for this, have you tried it and whether it works for your scenario?

Regards,

Ethan

Yup it works good. Just have to rotate the polygon half of whatever angle I pass it in to line it up correctly.

Hi Dan,

Thanks for your share, it should be helpful if anybody have the same requirement.

Regards,

Ethan