Determine the side length of the regular hexagon which an arbitrary point lies on

210 Views Asked by At

We've found ourselves having to solve this peculiar problem for a plastic part that we are machining. I'll spare you the details.

Given an arbitrary point $P = (x, y)$ on the cartesian plane, and "rings" of regular hexagons spaced around the origin (with two of the sides parallel to the x axis), determine the side length of the hexagon that $P$ lies on.

I'd like to implement this function in a computer program so that, given the arbitrary point $(x,y)$, the output of the function $L$ is the side length of the relevant hexagon i.e. $f(P) = L$.

Because all hexagons form concentric layers around the origin, and are all orientated the same way ("growing" outwards), the answer is exact i.e. there is only one exact hexagon orientated this way that any arbitrary point on the plane could possibly lie on.

I'd like to stress that the point is completely arbitrary i.e. it is most certainly not a vertex of the hexagon, but it may be.

I've added a visual diagram of two examples of specific points and the hexagons which they lie on, as well as their function values, for visualization purposes.

Example of two points on their corresponding L values to be determined

3

There are 3 best solutions below

1
On BEST ANSWER

Start by taking the absolute values of each of $x$ and $y$. This obviously doesn't change which hexagon your point lies on, but you now know it will be either on its top side, or the upper right side.

The line through the origin formed by the upper right corners of all the possible hexagons has slope $\sqrt3$, so if $y \ge \sqrt3\cdot x$ you know the point is on a top side. Then the side length is $\frac{2y}{\sqrt3}$.

Otherwise it is on the sloping side, whose slope is $-\sqrt3$. Continuing along that side until the $x$-intercept gives us $x+y/\sqrt3$.

All in all, $$ f(x) = \begin{cases} 2|y|/\sqrt3 & \text{if } |y| \ge\sqrt3|x| \\ |x| + |y|/\sqrt3 & \text{otherwise} \end{cases} $$

0
On

Rotate the point by $\pi/3$ until it's in the upper cone (until $y \geq \tan(\pi/3) |x|$). Then calling $y_n$ the new rotated height, we can draw a right triangle joining the top right vertex of the hexagon and the origin, the length of the side should be two times the length of the horizontal leg, in this case $2 y_n / \tan(\pi/3)$ if I'm not mistaken.

0
On

Suppose the given point is P(x, y). Firstly, if $y = 0$ then $P$ is a vertex on the $x$-axis, and therefore, the side length $L=|x|$.

Secondly, if $x = 0$ , then $L = \dfrac{2}{\sqrt{3}} |y| $.

Otherwise, find the angle that $P$ makes with the positive $x$-axis. That is, find

$ \phi = ArcTan2(x, y) $ , such that $0 \le \phi \lt 2 \pi$

Compute the index of the sector that $\phi$ lies in. That is, compute,

$ k = \lfloor \dfrac{\phi}{\pi / 3 } \rfloor + 1 $

Next, rotate the point $P$ about the origin by an angle $ \theta(k) = (2-k) \dfrac{\pi}{3} $

Let the rotated point be $Q(x', y')$ then

$ x' = \cos \theta(k) x - \sin \theta(k) y $

$y' = \sin \theta(k) x + \cos \theta(k) y $

Now $Q$ lies in the "top" sector, so it lies on a horizontal line segment of the hexagon, and therefore,

$ L = \dfrac{2}{\sqrt{3}} y' $

Verification: Let $P = (1.5, 1)$, then $ \phi = \tan^{-1}(\dfrac{2}{3}) $ and $k = 1$, and $ \theta(k) = (2 - 1) \dfrac{\pi}{3} = \dfrac{\pi}{3} $

Hence the point Q(x', y') has the following coordinates:

$x' = 1.5 (1/2) - \sqrt{3}{2}$

$y' = 1.5 \sqrt{3}{2} + (1/2)$

Therefore, $ L = \dfrac{2}{\sqrt{3}} ( 1.5 \dfrac{\sqrt{3}}{2} + (1/2) ) = 1.5 + \dfrac{1}{\sqrt{3}} $

The line segment that point $P$ should lie on has the equation

$ y = - \sqrt{3} (x - L) $

$ 1 = -\sqrt{3} (1.5 - (1.5 + \dfrac{1}{\sqrt{3}}))$ is indeed an identity.