Link to home
Start Free TrialLog in
Avatar of shpark82
shpark82

asked on

graphing a polygon with double values

I'm looking to generate plotted Point graph output using a graphic library that creates a 2D set of cartesian axes, plots points[i] for i = 0 to points.length-1. Also draws lines between each of points[n] and points[n+1] for n = 0 to points.length-2. Also plot a line from points[points.length-1] to points[0].

Here is my code but it doesn't work....please help!


import java.lang.Math.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.Polygon;
import java.awt.Graphics;

/* more code above but not necessary to show i don't think */

public void draw ( Point[] points, String[] text )
            {
                  x = new long[points.length];
                  y = new long[points.length];
                  tempPoint = new Point[points.length];
                  Graphics g1 = null;


                  for (int i = 0; i < points.length; i++)
                  {
                        x[i] = points[i].x();
                        y[i] = points[i].y();
                        tempPoint[i] = new Point(x[i], y[i]);
                  }

                  LongPolygon g = new LongPolygon(tempPoint);



                  g1.drawPolygon(g);
                  System.out.println(text);
            }      

private class LongPolygon extends Polygon
      {
            private Point[] tempPoints;

            public LongPolygon(Point[] points)
            {
                  tempPoints =  points;
            }
      }            
ASKER CERTIFIED SOLUTION
Avatar of ADSLMark
ADSLMark

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial