'How to know all the 6 hexagon vertices given two vertices only?
I am trying to let the program draw a hexagon, The program should let the user enter the coordinates of two points only, I will assume those points are the terminals of a side, then I need to calculate the coordinates of other four points, but how? P.S: I use the library graphics.h that contains draw polygon which requires 2 arrays of x and y coordinates for all points
Solution 1:[1]
Given two points (x1, y1), (x2, y2), the next point on the hexagon can be computed with the formulas
dx = x2 - x1
dy = y2 - y1
x3 = x2 + ((?3)/2) dx - (1/2) dy
y3 = y2 + (1/2) dx + ((?3)/2) dy
These are derived from general rotation formulas; note that cos 60° = (?3)/2 and sin 60° = 1/2.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Eisenstat |
