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
Asked
Active
Viewed 127 times
-1
-
4Welcome to stackoverflow.com. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Jun 02 '18 at 20:29
-
1Code. We need to see your code to see what you have tried to implement. Now, if this question is purely computational (i.e. can someone please calculate these coordinates for me) then there are more appropriate sites for this question than this one. – eric Jun 02 '18 at 20:32
-
Draw a (regular) hexagon on a piece of paper. Draw a dot in the centre and lines from that dot to the vertices, thus creating *equilateral triangles*. Draw the circumscribing circle faintly. Make the line for the edge you know a bit heavier. – Andrew Morton Jun 02 '18 at 20:40
1 Answers
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.

David Eisenstat
- 64,237
- 7
- 60
- 120