Is a point inside regular hexagon

前端 未结 8 1694
心在旅途
心在旅途 2020-12-31 08:59

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

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 09:16

    Looks like you know general solution: "It seems like overkill to use...". So here is my idea:

    Calculate distance from point to center and let's call it l.

    Then you can compare it to inradius (r) and circumradius (R). if l < r then point is inside hexagon, if l > R then outside. If r < l < R then you have to check against each side respectively, but since R - r is very small (13% of length of side of hex) so probability that you will have to do complex calculations is tiny.

    Formulas can be found here: http://mathworld.wolfram.com/Hexagon.html

提交回复
热议问题