Note that there are some explanatory texts on larger screens.

plurals
  1. POTest of Point inside polygon in Android
    text
    copied!<p>The other day I did a class in Java to calculate if a <code>point(X,Y)</code> is inside a polygon. (<code>X</code> and <code>Y</code> are <code>double</code>, because will be geo-coordinates).</p> <p>I know that Java has the class <code>Polygon</code>, but I had to use <code>Path2D</code> and <code>Point2D</code>, because <code>Polygon</code> don't allow <code>double</code>'s, just integers :(</p> <p>Once I have the polygon done in <code>Path2D</code>, I used the method <code>contains</code> (<code>Path2D</code> had it), and my problem was solved.</p> <p>But now, I want to import to Android, and the problem is here, because <code>Path2D</code> needs to import:</p> <pre><code>import java.awt.geom.Path2D; import java.awt.geom.Point2D; </code></pre> <p>and in Android don't exist awt, so I can't use.</p> <p>So, is there any class similar to <code>Path2D</code> that had <code>contains</code> method? or I have to calculate by myself?</p> <p>Here is how I did in Java using <code>Path2D</code>:</p> <pre><code>private void ConstructPolygon(Vector&lt;Point2D&gt; coodinates) { this.polygon.moveTo(coodinates.get(0).getX(), coodinates.get(0).getY()); //System.out.println(coodinates.get(0).getX() + " " + coodinates.get(0).getY()); //System.out.println("asda"); for(int i = 1; i &lt; this.num_points; i++) { //System.out.println(coodinates.get(i).getX() + " " + coodinates.get(i).getY()); this.polygon.lineTo(coodinates.get(i).getX(), coodinates.get(i).getY()); } this.polygon.closePath(); } public boolean InsideCity(Point2D punto) { return this.polygon.contains(punto); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload