java 如何检查点是否在多边形内

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15958434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:26:47  来源:igfitidea点击:

How to check if a Point is inside a Polygon

javalocationentitycoordinates

提问by user1621988

I've got a Polygon:

我有一个Polygon

image

图片

I want to check if the Location of an Entity is inside this Polygon.
As example x:5 and y:5, How can I make a check to see if this Coordinate is inside this Polygon (Java)?

我想检查一个实体的位置是否在这个里面Polygon
例如 x:5 和 y:5,我怎样才能检查这个坐标是否在这个多边形内(Java)?

回答by Joban Dhillon

If you create the polygon using the Polygonclass that is included with java use the contains()method.

如果您使用Polygonjava 中包含的类创建多边形,请使用该contains()方法。

http://docs.oracle.com/javase/6/docs/api/java/awt/Polygon.html

http://docs.oracle.com/javase/6/docs/api/java/awt/Polygon.html

Take a look at the method summary:

看一下方法总结:

contains(int x, int y)- Determines whether the specified coordinates are inside this Polygon

contains(int x, int y)- 判断指定的坐标是否在这个里面 Polygon