Advertisement

Orienting a hexagon around another hexagon without 60-degree turns

Started by July 07, 2020 04:59 PM
12 comments, last by alvaro 4 years, 6 months ago
#include <complex>

typedef std::complex<double> C;

C rotation_to_align_hex(C original, C target) {
  C o6 = std::pow(original, 6);
  C t6 = std::pow(target, 6);
  C r6 = t6 / o6;
  return std::pow(r6, 1.0/6.0);
}

Following the initial suggestion of using complex numbers, this works beautifully. You can plug in the orientation of any of the vertices of the two hexagons (as length-1 complex numbers) and it will return the smallest rotation needed to line up the hexagons.

alvaro said:
Following the initial suggestion

It was your introductions from years ago that made me using complex numbers for 2D rotations, and it's really convenient. : )
Though, i wonder why division gives difference of angle, pow multiplies angle, arg gives angle, conj gives dot product, etc. There might be some deeper sense for the mathematician, but i'm still missing that :D

Your example assumes regular hexagons. I thought this is not the case and they can be irregular. If i got this wrong there is no need to iterate over all 6 points ofc, and no need for weights either.

Advertisement

Oh, I'm glad to hear my years-long propaganda campaign for complex numbers is having an effect! ?

It's too hard to explain in this forum why division gives difference of angles, etc. Maybe this might help: https://www.youtube.com/watch?v=mvmuCPvRoWQ

I don't know even know what the desired behavior is in the case of irregular polygons, so I just went with the case I understood, and I demonstrated how using complex numbers in the way you indicated does work beautifully.

This topic is closed to new replies.

Advertisement