![]() |
|
#1
|
|||
|
|||
Finding coordinates of a polyhexHi,
I am pasting here code for finding coordinates of a regular polygon. CPP / C++ / C Code:
What will be the code for finding coordinates of a polyhex, let suppose there are 20 or 50 points, how to arrange these points in a polyhex? Thanks in advance Vikash |
|||
|
#2
|
|||
|
|||
Re: Finding coordinates of a polyhexQuote:
Hmmm... I can't see where that code can find the coordinates of anything but a straight line. Wait while I test it--- Tick Tick Tick Well, after cleaning up your print statement for the Y coordinate and resolving the undefined behavior caused by adding stuff to variables x_coord[i] and y_coord[i] where you never initialized them and getting rid of the non-standard getch() function call (since my system doesn't have it) and changing non-standard definition void main() to int main(), I get the following output: Code:
Now, I see that it is, indeed, showing me the coordinates of a straight line. So: Before trying to change the program to handle N-sided polygons, how about going back to wherever you got the formulas (or revisiting whatever thought process lead to the formulas) and let's get a regular hexagon, OK? Regards, Dave Footnote: Judging by some of your variable names and calculations, I perceive that you want that particular program to calculate vertices of a regular hexagon with side length of 10 units and centered at (x,y) = (10,10). Of course, I could be wrong. But... By my reckoning, and for your reference: A regular hexagon with side length 10 and centered at (10,10) might have vertices at the following coordinates (approximated to six decimal places): Code:
Last edited by davekw7x : 06-Dec-2008 at 16:56.
|
|
#3
|
|||
|
|||
Re: Finding coordinates of a polyhexSorry, I forget to write sin & cos for y_coord & x_coord respectively. Initilize array x_coord[] & y_coord[] with zero.
CPP / C++ / C Code:
Now the code will gives you coordinates of a regular hexagon. My problem is : I have let say 20 or 50 points, I want to arrange these points in a polyhex, i.e., what will be the coordinates for those points in a polyhex Thanks Vikash |
|
#4
|
|||
|
|||
Re: Finding coordinates of a polyhexQuote:
Well, I have a problem, too. Here goes. I modified your original program as follows:
Code:
Now, these are not (that's not) the vertices of a regular hexagon. See Footnote. I don't know whether you are actually running something else or whether you didn't actually inspect the outputs from your program. I can't see how we can help you understand how to modify your code to give results for N-sided regular polygons if it doesn't work as expected for the given program (which is specialized for N = 6). So I respectfully suggest:
Regards, Dave Footnote: I have attached a plot of those points. |
|
#5
|
|||
|
|||
Re: Finding coordinates of a polyhexHi,
Sorry for that much trouble. Here I am pasting the complete code with output. CPP / C++ / C Code:
Now, let say if we have 10 points we can build a dihex. With 17 points we can build a trihex. The question is : 1. How we can build this dihex, trihex, tetrahex & so on. 2. If suppose we have 11 to 16 points, I want to build a dihex with 10 points & the remaining points should arrange itself with dihex which satisfy the properties of a regular hexagon, e.g. all the points which have arranged itself with dihex should have an exterior angle of 60 degree, vertex angle of 120 degree and so on. 3. Same with 20 or 50 points, i.e. go on building a polyhex, & the remaining points should satisfy the properties of a regular hexagon. All the remaining points should be attached to the polyhex. Thanks Vikash |
|
#6
|
|||
|
|||
Re: Finding coordinates of a polyhexQuote:
Quote:
Quote:
Since we already have a way of building a hexagon, I would start there and see how to build two hexagons that would fit together to make a dihex: I might make a function that builds a hexagon with a given side length and center coordinates. I might try a few cases and inspect the results visually. Then try to see how to combine several in a program in some useful way. Suppose that the first hexagon will have center (x0, y0). DIhex figures are typically drawn so that the second hexagon is drawn with center (x0+1.5*side_length, y0-sqrt(3)/2*side_length). (Try it.) Now I can make two distinct hexagons in a program with a function like that. CPP / C++ / C Code:
I might end up with two sets of six coordinate pairs. Code:
Now, I might visually inspect them to find the common side, noting that, of the 12 vertices shown, 10 are unique. Now it's time for you do make some decisions: If you were going to plot the figures, would you eliminate that common line? The way that you generate the points, the line between point 5 and point 0 of the first hexagon is co-located with the line from point 2 to point3 of the second. Is there a way of generating the points in order so that the last point of the first hexagon is the first point of the second. You can "rotate" the figures by shifting the coordinate sets. Stuff like that. Anyhow, maybe that's a start. Regards, Dave Footnote: The "gen_hexagon()" function that I have in mind would create the hexagon with center at the origin and then call a "translate()" function to put it at the specified center: CPP / C++ / C Code:
Maybe I would create all hexagons with center (0,0) and then call translate() and rotate() functions to get them lined up in such a way that I could eliminate the common lines. All of these could be specialized for hexagons (rather than generic graphics transformations), since that's all that is required. Or some such thing. Also, in C or C++, I probably wouldn't have separate arrays for the coordinates; I would probably have some kind of "point" struct that is defined to have two values corresponding to x and y coordinate values. In C++ I might even have a "hexagon" class that would give the ability to create, translate, rotate, etc., hexagon objects. I have attached a drawing of the output of the two-hexagon program(without trying to eliminate the lines between common vertices). Last edited by davekw7x : 07-Dec-2008 at 14:53.
|
|
#7
|
|||
|
|||
Re: Finding coordinates of a polyhexHi,
Thanks a lot for your help. I think this is what you mean. CPP / C++ / C Code:
Please, tell me 1. how to remove common line, 2. how to "rotate" the figures, & 3. second hexagon can be at any side of the first hexagon, so what will be the centers(x,y) of second hexagon in that case. The code suggested by you is really a good start for me. Thanks a lot. Thanks Vikash |
|
#8
|
|||
|
|||
Re: Finding coordinates of a polyhexQuote:
Quote:
CPP / C++ / C Code:
Quote:
For example, the way that we are drawing the hexagons (so far), the first virtex is always to the right of the origin, and subsequent points march counterclockwise around the figure. For my example, I chose to put the second down and to the right of the first. Building on your example, the center of the first was at (10,10), and my addition made the center of the second at (10*1.5*side_length, 10-sqrt(3)/2*side_length). Now if I rotate the second figure three clicks to the left (3*60 degrees) here are the coordinates of the composite figure: Code:
So: Plot the two (open-ended) figures separately or make a composite by starting at the first point of the first and going through all points, and the result will be a closed dihex. See attachment. Bottom line: You are creating a specialized program to do something special. I don't really know what the final product is supposed to be, so I have tried to convey some thought processes that can approach the problem, starting with your original hexagon-creating program. There are other ways of doing stuff like this. (Generic plotting programs that find ways of eliminating common lines from collections of independent figures. Stuff like that). Starting with three functions (generate_hexagon, translate_hexagon, rotate_hexagon) you can create as many vertices of as many of the blasted things anywhere you want them to be. It is up to you to make the decision as to how you are going to draw the figures (if, indeed, you are going to draw them) and how to handle fewer points and more points, etc. For example: Where will you add the third hexagon if there are more points? How can you arrange the coordinates so that you can start at the first point and end at the last point? (Imagine yourself drawing the pictures with a pencil. How would you draw a trihex without picking up the pen from the paper? Can you make a program that will do that? Start with specifics: one hexagon, two hexagons, etc. Get some hex nuts from the hardware store and play with some configurations of polyhexes to decide how you want to build them ![]() Look for inspiration at places like: http://www.asahi-net.or.jp/~uy7t-isn...es/Trihex.html Regards, Dave Last edited by davekw7x : 08-Dec-2008 at 10:00.
|
|
#9
|
|||
|
|||
Re: Finding coordinates of a polyhexHi Dave,
Thanks a lot for your help & guidance. Regards, Vikash |
|
#10
|
|||
|
|||
Different problemHi Dave,
I am stuck at some problem, can you please take a look at post "Finding alternate paths using Dijkstra algorithm". Please help me out in solving it. Thanks in advance Vikash |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Picture control and mouse coordinates | senor.ram | MS Visual C++ / MFC Forum | 2 | 02-Jul-2007 08:00 |
| coordinates of a circle | IRONMAN | C++ Forum | 2 | 02-Jun-2006 14:31 |
| Passing mouse coordinates to another program | aditya_naidu1 | MS Visual C++ / MFC Forum | 2 | 20-May-2005 10:08 |
| Finding a word in a 2d grid | The_Kingpin | C Programming Language | 4 | 24-Feb-2005 20:53 |
| 3D graphics coordinates | TekiFreek | C++ Forum | 0 | 18-Apr-2004 23:40 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The