#Trying to connect points on a JFrame using a Line Segment Class, but failing at doing so.

28 messages · Page 1 of 1 (latest)

thorny talon
#

No matter what I try, I can't seem to get the lines to connect after making a LineSegment using the current and next point on the Frame. I'm confused on what to do and I feel like I'm going in circles. Could someone help out?

desert skyBOT
#

Hey, @thorny talon!
Please remember to /close this post once your question has been answered!

thorny talon
#

Using IntelliJ for a Maven project, don't know if that matters.

desert skyBOT
#

<@&765578700724371486>

Requested by Astral#4398
thorny talon
#

Yeah.

thorny talon
# median nest graphics?

So, I'm trying to create a program that will essentially take a list of points from a Text File, generate a polygon out of those points, and determine the shape and print it to the user.

cloud turret
thorny talon
#

How come?

#

I've been trying paint components, but so far nothing has been working.

cloud turret
thorny talon
#

Ok, so I actually managed to fix the reason as to why it wasn't drawing the line segment.

#

But now I want to try and improve my Algorithm for determining the Shape.

#

Since I'm wondering if the way it determines the Shape might always result in a convex polygon being the result.

#

Would it be better for me to determine it in a different way?

cloud turret
#

make a while loop and ask for polygon x, y

thorny talon
#

We're not allowed to use a Polygon class in the requirements.

cloud turret
#

if player input is "generate" then stop loop and drae

thorny talon
#

At least, based off the UML Diagram.

cloud turret
thorny talon
#

The way we do it is by having an Array of Points, and a GeometricObject Array, both of which will have equal values.

#

We then pass drawn line segments within the GraphDisplay class into the GeometricObject Array so it displays and creates a shape with the points.

#

I just want to try figuring out a new way of determining the shape that would be more reliable.

#
public class Algorithms{
    public static String polygonType(Point[] points){
        if(points.length < 3) return "A Point or Line Segment is not enough to determine a Polygon.";
        if(points.length == 3) return "The shape is a Triangle.";
        boolean convexPoly = true;
        boolean rectilinearPoly = true;
        for(int i = 1; i < points.length - 1; i++){
            double angleMeasurement = 0;
            if(i == points.length) angleMeasurement = points[i].angleCalc(points[i-1], points[i], points[0]);
            else angleMeasurement = points[i].angleCalc(points[i-1], points[i], points[i+1]);
            if(angleMeasurement != 90) rectilinearPoly = false;
            if(angleMeasurement >= 180) convexPoly = false;
        }
        if(points.length == 4 && rectilinearPoly == true) return "The shape is a Rectangle.";
        else if(rectilinearPoly == true) return "The shape is a Rectlinear Polygon.";
        else if(convexPoly == true) return "The shape is a Convex Polygon.";
        else return "The shape is a Simple Polygon.";

    }

}```
#
 public double angleCalc(Point p1, Point center, Point p2){
        return (Math.atan2(p2.getY() - center.getY(), p2.getX() - center.getX()) - Math.atan2(p1.getY() - center.getY(), p1.getX() - center.getX()));
    }```