具有双坐标的多边形 [英] Polygons with Double Coordinates

查看:158
本文介绍了具有双坐标的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些关于多边形的问题,它们是Double type ... Point
我必须做的是给出点,创建多边形,然后测试一个具体点是否在多边形内。



所以我知道在Java中有一个叫Polygon的类,它被这样使用:(triangle)

  int valoresX [] = {100,150,200}; 
int valoresY [] = {100,200,100};
int n = valoresX.length;
多边形城市=新的多边形(valoresX,valoresY,n);

但是我的多边形必须是Double类型,而不是int )

  Double valoresX [] = {1000.10,150.10,200.10}; 
Double valoresY [] = {100.10,200.10,100.10};

在我的项目中,我不需要在小程序或类似程序上绘制它,我只需要计算如果点在里面或不是。



所以我的问题是:



有什么办法做多边形双重协调,允许计算如果点(双)在多边形内部吗?



感谢所有!!!



Shudy

解决方案

您可以使用 Path2D.Double

  Path2D path = new Path2D.Double(); 

path.moveTo(valoresX [0],valoresY [0]); (int i = 1; i< valoresX.length; ++ i){
path.lineTo(valoresX [i],valoresY [i]);

}
path.closePath();

另请参阅这个问题:



< a href =https://stackoverflow.com/questions/11465330/implementing-polygon2d-in-java-2d>在Java 2D中实现Polygon2D


I have some questions about Polygons with points of Double type... What I have to do, is given points, create the polygon, and then, test if 1 concrete point is inside the polygon or not.

so I kwnow that in Java there's a class, called Polygon, and is used like that: (triangle)

int valoresX[] = { 100, 150, 200 };
int valoresY[] = { 100, 200, 100 };
int n = valoresX.length;
Polygon city= new Polygon(valoresX,valoresY,n);

But my "polygons" has to be of "Double" type, not "int" (easy example)

Double valoresX[] = { 1000.10, 150.10, 200.10 };
Double valoresY[] = { 100.10, 200.10, 100.10 };

In my project i dont really need to paint it on an applet or similar, I just need to calculate if the point is inside or not.

So my question is:

Is any way to do polygons with double coordenates , that allow to calcultate if the point(double) is inside the polygon or not?

Thanks for all!!!

Shudy

解决方案

You can do this with Path2D.Double:

Path2D path = new Path2D.Double();

path.moveTo(valoresX[0], valoresY[0]);
for(int i = 1; i < valoresX.length; ++i) {
   path.lineTo(valoresX[i], valoresY[i]);
}
path.closePath();

See also this question:

Implementing Polygon2D in Java 2D

这篇关于具有双坐标的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆