里面正六边形点 [英] Is a point inside regular hexagon

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

问题描述

我在寻找建议继续进行的最佳方式。我试图找出是否一个给定的点A:(A,B)是一个正六边形,与中心O定义内:(X,Y)和外接圆直径。

I'm looking for advice on the best way to proceed. I'm trying to find whether a given point A:(a, b) is inside a regular hexagon, defined with center O:(x, y) and diameter of circumscribing circle.

这似乎有点小题大做使用光线投射,或清盘号来确定这一点,对于这样一个简单的例子,而我目前正在研究发现该行OA的角度(从水平)的选项, 正常化(可能不是正确的字)入6等边三角形中的一个,看是否这个新的点位于该三角形内。

It seems like overkill to use Ray-casting, or Winding-number to determine this, for such a simple case, and I'm currently looking at the option of finding the angle (from horizontal) of the line OA, and "normalising" (probably not the right word) it into one of the 6 equilateral triangles and seeing if this new point lies within this triangle.

我得到我失去了一些东西简单的感觉,并有一个简单的方法(或者,如果我真的很幸运,一个Java API),以简单而有效地做到这一点。

I get the feeling I'm missing something simple, and there's an easy way (or if I'm really lucky, a Java API) to do this simply and efficiently.

感谢您的帮助。

修改:该六边形的取向使得所述侧边中的一个是平与水平

Edit: The hexagon is oriented such that one of the sides is flat with the horizontal.

推荐答案

您可以使用公式为每个六边形的两侧;与他们可以查出一个给定的点是在同一个半平面为六角形的中心。

You can use the equations for each of the sides of the hexagon; with them you can find out if a given point is in the same half-plane as the center of the hexagon.

例如,右上侧具有等式:

For example, the top-right side has the equation:

-sqrt(3)x - y + sqrt(3)/2 = 0

您插上点的这个坐标,然后该中心的坐标。如果结果具有相同的符号,则该点是在底左半平面(因此它可以是六边形内部)。

You plug in this the coordinates of the point and then the coordinates of the center. If the results have the same sign, then the point is in the bottom-left half-plane (so it may be inside the hexagon).

您然后使用他人双方的方程重复。
请注意,此算法将工作的任何凸多边形

You then repeat by using the equations of the others sides.
Note that this algorithm will work for any convex polygon.

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

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