Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Point in poly line

Help
Anonymous
2012-12-04
2012-12-12

  • Anonymous
    2012-12-04

    Hello

    I am trying to do this

                    boolean checkPoly = true;
                        Point2D[] points = new Point2D[areaArray.size()];
    
                        for ( int i = 0; i < areaArray.size(); i ++)
                        {
                            AreaMarkClass areaMark = areaArray.get(i);
                            double a = Double.valueOf(areaMark.getLatitude());
                            double b = Double.valueOf(areaMark.getLatitude());
                            Point2D point = new Point2D(a,b);
                            points[i] = point;
                        }
    
                        Polygon2D polygon2d = new Polygon2D();
                        double a = p.getLatitudeE6();
                        double b = p.getLongitudeE6();
                        Point2D point = new Point2D(a,b);
                        polygon2d.addVertex(point);
                        checkPoly = polygon2d.contains(point);
    

    The problem that I am facing is ,  whatever i do ,
    Polygon2D polygon2d = new Polygon2D(doublex, doubley);
    Polygon2D polygon2d = new Polygon2D(Point2d);
    Polygon2D polygon2d = new Polygon2D();

    It just says Cannot instantiate the type Polygon2D.. How can i initialize this Polygon2D

     
  • David
    David
    2012-12-04

    Hi,

    The type Polygon2D is an interface, and can therefore not be instantiated.
    You can use "SimplePolygon2D", that implements the Polygon2D interface. This should do the job!

    Hope this helps,
    David

     

  • Anonymous
    2012-12-04

    thats cool it worked, tho i have one more question , I tried finding Polygon2DUtil, but Its not in javaGeom 0.11.1 . Which lib got this class?

     
  • David
    David
    2012-12-04

    Hi,

    the class has been renamed in "Polygons2D" (to have naming conventions similar to the java Collection package).
    You can find  API for this class here:
    http://geom-java.sourceforge.net/api/math/geom2d/polygon/Polygons2D.html

    tell me if you encounter any other problems!
    regards,

    David

     

  • Anonymous
    2012-12-05

    Yes, thanks david you were really helpful. However I am facing a new problem and I can't figure to fix this

    AreaMarkClass areaMark = areaArray.get(i);
                            double a = Double.valueOf(areaMark.getLatitude());
                            double b = Double.valueOf(areaMark.getLongitude());
                            Point2D point = new Point2D(a,b);
                            points[i] = point;
    

    this is my code
    my double a and b values are lets say 4.1036, 5.0231 however Point2D point = new Point2D(a,b); giving error

    Could not find class 'java.awt.geom.Point2D$Float', referenced from method math.geom2d.Point2D.getAsFloat

    Am I missing something important?

     
  • David
    David
    2012-12-05

    Hi,

    this is a strange bug, as the method math.geom2d.Point2D.getAsFloat() is not used in the constructor of Point2D.

    The way you are constructing new instance Point2D is the right way.

    Some questions:
    * have you checked there is no conflict in your imports between math.geom2d.Point2D and java.geom.Point2D ?
    * Do you develop for the android platform ? I am not sure about the compatibility of javaGeom for android. I have removed inheritance of Point2D to java classes, but maybe some compilers requires the java awt part to be in the path ?

    I'm sorry to say that I can't help more…