Help please Code Polygon

Hello everyone I need some help I created a Polyline and through it I create the other objects as a rectangle, you only understand that it created a problem that my CS0116 namespace is I don’t know how to solve it, help me later I post the entire code of the polyline as I did ok

Hello @mickaelschwedler

At first glance, looking at bracket placement, it looks like the GetPolygon method is within the namespace, but outside of the class. Can you verify that?

Regards,
Jerry.

Hi, how are you? GetPolygon is outside the LwPolyline class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp2.Entities
{
public class LwPolyline
{
private List vertexes;
private PolylineTypeFlags flags;
private double thickness;
public LwPolyline()
: this(new List(), false)
{
}
public LwPolyline(List vertexes, bool IsClosed)

        {
        if (vertexes == null)
            throw new ArgumentNullException(nameof(vertexes));
        this.vertexes = vertexes;
        this.flags = Isclosed ? PolylineTypeFlags.CloseLwPolyline : PolylineTypeFlags.OpenLyPolyline;
        this.thickness = 0.0;
        }
    public List<LwPolylineVertex> Vertexes
        {
        get { return vertexes; }
        set
            {
            if (value == null)
                throw new ArgumentNullException(nameof(vertexes));
            this.vertexes = value;
            }

        }
    internal PolylineTypeFlags Flags
        {
        get { return this.flags; }
        set { this.flags = value; }
        }
    public bool Isclosed
        {
        get { return (this.flags & PolylineTypeFlags.CloseLwPolyline) == PolylineTypeFlags.CloseLwPolyline; }
        set { this.flags = value ? PolylineTypeFlags.CloseLwPolyline : PolylineTypeFlags.OpenLyPolyline; }

        }

    public double Thickness
        {
        get { return thickness; }
        set { thickness = value; }
        }
    }
}

Here is the Method class here is the methods I want to use.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using WindowsFormsApp2.Entities;
using WindowsFormsApp2.Methods;
using System.Collections;
using System.ComponentModel;

namespace WindowsFormsApp2.Methods
{
public static class Method
{
public static double LineAngle(Vector3 start, Vector3 end)
{
double angle = Math.Atan2((end.Y - start.Y), (end.X - start.X) * 180.0 / Math.PI);
if (angle < 0.0)
angle += 360.0;
return angle;
}
public static Ellipse GetEllipse(Vector3 center, Vector3 firstPoint, Vector3 secondPoint)
{
double major = center.DistanciaFrom(firstPoint);
double minor = center.DistanciaFrom(secondPoint);
double angle = LineAngle(center, firstPoint);
Ellipse elp = new Ellipse(center, major, minor);
elp.Rotation = angle;
return elp;
}
public static Vector3 LineLineIntersection(Line line1, Line line2, bool extendend = false)
{
Vector3 result;
Vector3 p1 = line1.StartPoint;
Vector3 p2 = line1.EndPoint;
Vector3 p3 = line2.StartPoint;
Vector3 p4 = line2.EndPoint;

        double dx12 = p2.X - p1.X;
        double dy12 = p2.Y - p1.Y;
        double dx34 = p4.X - p3.X;
        double dy34 = p4.Y - p3.Y;

        double denominator = (dy12 * dx34 - dx12 * dy34);
        double K1 = ((p1.X - p3.X) * dy34 + (p3.Y - p1.Y) * dx34) / denominator;

        if (double.IsInfinity(K1))
            return new Vector3(double.NaN, double.NaN);

        result = new Vector3(p1.X + dx12 * K1, p1.Y + dy12 * K1);

        if (extendend)
            return result;
        else
            {
            if (IsPointOnLine(line1, result) && IsPointOnLine(line2, result))
                return result;
            else
                return new Vector3(double.NaN, double.NaN);
            }
        }
    private static bool IsPointOnLine(Line line1, Vector3 point)
        {
        return IsEqual(line1.Length, line1.StartPoint.DistanciaFrom(point) + line1.EndPoint.DistanciaFrom(point));
        }
    private static double epsilon = 1e-12;
    private static bool IsEqual(double d1, double d2)
        {
        return IsEqual(d1, d2, epsilon);
        }
    private static bool IsEqual(double d1, double d2, double epsilon)
        {
        return IsZero(Math.Abs(d1 - d2), epsilon);
        }
    private static bool IsZero(double d, double epsilon)
        {
        return d >= -epsilon && d <= epsilon;
        }
    public static Circle GetCircleWith3Point(Vector3 p1, Vector3 p2, Vector3 p3)
        {
        double x1 = (p1.X + p2.X) / 2;
        double y1 = (p1.Y + p2.Y) / 2;
        double dx1 = p2.X - p1.X;
        double dy1 = p2.Y - p1.Y;

        double x2 = (p2.X + p3.X) / 2;
        double y2 = (p2.Y + p3.Y) / 2;
        double dx2 = p3.X - p2.X;
        double dy2 = p3.Y - p2.Y;

        Line line1 = new Line(new Vector3(x1, y1), new Vector3(x1 - dy1, y1 + dx1));
        Line line2 = new Line(new Vector3(x2, y2), new Vector3(x2 - dy2, y2 + dx2));

        Vector3 center = LineLineIntersection(line1, line2, true);

        double dx = center.X - p1.X;
        double dy = center.Y - p1.Y;

        double radius = Math.Sqrt(dx * dx + dy * dy);

        return new Circle(center, radius);
        }
    public static Arc GetArcWith3Points(Vector3 p1, Vector3 p2, Vector3 p3)
        {
        double start, end;
        Arc result = new Arc();

        Circle c = GetCircleWith3Point(p1, p2, p3);

        if (c.Radius > 0)
            {
            if (DeterminePointOfLine(new Line(p1, p3), p2) < 0)
                {
                start = LineAngle(c.Center, p3);
                end = LineAngle(c.Center, p1);
                }
            else
                {
                start = LineAngle(c.Center, p1);
                end = LineAngle(c.Center, p3);
                }
            if (end > start)
                end -= start;
            else
                end += 360.0 - start;

            result = new Arc(c.Center, c.Radius, start, end);
            }
        return result;
        }
    private static double DeterminePointOfLine(Line line, Vector3 v)
        {
        return (v.X - line.StartPoint.X) * (line.EndPoint.Y - line.StartPoint.Y) - (v.Y - line.StartPoint.Y) * (line.EndPoint.X - line.StartPoint.X);
        }
    }
public static LwPolyline GetPolygon(Vector3 center,Vector3 secondPoint, int inscribed)
    {
    List<LwPolylineVertex> vertexes = new List<LwPolylineVertex>();
    double sidesQty = 0;
    double sides_angle = 360.0 / sidesQty;
    double radius = center.DistanciaFrom(secondPoint);
    double lineangle = Methods.Method.LineAngle(center, secondPoint);

    if (inscribed == 1)
        {
        lineangle -= sides_angle / 2.0;
        radius /= Math.Cos(sides_angle / 180 * Math.PI / 2.0);
        }
    for (int i = 0; i < sidesQty; i++)
        {
        double x = radius / Math.Cos(lineangle / 180.0 * Math.PI);
        double y = radius / Math.Sin(
            lineangle / 180.0 * Math.PI);
        vertexes.Add(new LwPolylineVertex(x, y));
        lineangle += sides_angle;
        }
    return new LwPolyline(vertexes, true);
    }

}
        private static double DeterminePointOfLine(Line line, Vector3 v)
        {
            return (v.X - line.StartPoint.X) * (line.EndPoint.Y - line.StartPoint.Y) - (v.Y - line.StartPoint.Y) * (line.EndPoint.X - line.StartPoint.X);
        }
    }    // <-- This is the closing bracket of your Class
    
    public static LwPolyline GetPolygon(Vector3 center,Vector3 secondPoint, int inscribed)
    {
        List<LwPolylineVertex> vertexes = new List<LwPolylineVertex>();
        double sidesQty = 0;
        double sides_angle = 360.0 / sidesQty;
        double radius = center.DistanciaFrom(secondPoint);
        double lineangle = Methods.Method.LineAngle(center, secondPoint);

        if (inscribed == 1)
        {
            lineangle -= sides_angle / 2.0;
            radius /= Math.Cos(sides_angle / 180 * Math.PI / 2.0);
        }
        for (int i = 0; i < sidesQty; i++)
        {
            double x = radius / Math.Cos(lineangle / 180.0 * Math.PI);
            double y = radius / Math.Sin(
                lineangle / 180.0 * Math.PI);
            vertexes.Add(new LwPolylineVertex(x, y));
            lineangle += sides_angle;
        }
        return new LwPolyline(vertexes, true);
    }

}    // <-- This is the closing bracket of your Namespace

I formatted the last part of your code, and added comments (with arrows ← ) to indicate the closing bracket of your class and the closing bracket of your namespace.

If I’m not mistaken, the GetPolygon method is outside of the class, and it needs to be within the class. That is what the compiler error was saying.

1 Like

Thank you lack of attention right in the rush look what happens