Computer Science Canada Polygon Class |
Author: | batman [ Fri Nov 03, 2006 6:05 pm ] | ||
Post subject: | Polygon Class | ||
Alright, so im trying to work on a polygon class but im having troubles with it. I know how to do a rectangle class, a circle class but im kinda confused about polygons. I have no clue how to do a polygon class. I ve done all ta i could. Can someone help me draw a polygon????????? I think have to set the coordinates so the center is at 0,0 so some of te coordinates are negative. I need help fixing my code.
|
Author: | Booya [ Fri Nov 03, 2006 6:10 pm ] |
Post subject: | |
I think there is somethin wrong with ur code when you are trying to draw the polygon at the end. A polygon has six coordinates not 4. How u fix this im not sure because im newbe. |
Author: | ericfourfour [ Sat Nov 04, 2006 1:10 am ] |
Post subject: | |
Actually, a polygon as more than 2 sides a hexagon has 6. Your polygon should be made up of triangles though. That way it will be easier to deal with collisions. |
Author: | Dan [ Sun Nov 05, 2006 2:41 pm ] |
Post subject: | |
A polygon is any shape made up of at least 3 lines that conect to each other. Java has a bulit in polygon class that can show you how it is done. The easyest way to make a polygon is to take a 2d array of x and y quardents and then draw line segnements between the points. Then join the last x and y to the first x and y to complet the shape. |
Author: | Clayton [ Mon Nov 06, 2006 8:49 am ] | ||
Post subject: | |||
ie, in Turing the code would look something like this:
|
Author: | ericfourfour [ Mon Nov 06, 2006 4:54 pm ] | ||||||
Post subject: | |||||||
Well, if you wanna save yourself a Draw.Line use this.
To get the second id just add one to the first id and then get the remainder between that and the amount of positions.
I think (I'm not completely sure) in Java it would be:
|
Author: | gsquare567 [ Tue Nov 07, 2006 11:19 pm ] | ||
Post subject: | |||
what you have to do is make an array of the x's and y's and then they'll pair up when you drawPolygon.. eg.
|
Author: | gsquare567 [ Tue Nov 07, 2006 11:20 pm ] |
Post subject: | |
sorry instead of drawPoly i meant drawFill()... or you could just use draw() if you dont want it filled in =) check out the graphics and graphics2d classes in da api |
Author: | batman [ Wed Nov 08, 2006 2:36 pm ] |
Post subject: | Polygon |
Quote: // should give you a diamond =D int[] x = {-2, 0, 2, 0}; int[] y = {0, 2, 0, -2}; g2d.setColor(new Color(Color.Blue)); g2d.drawPoly(x,y);// something like this... probs ton of errors I already know how to draw a polygon thanks for the help though but i was talking about making it in a class then extending using an applet to draw the polyogn. I figured it out but thanks for the help. By the way grd.fillPolygon wont work unless u have x.length,x and y. Not just x,y. |
Author: | gsquare567 [ Fri Nov 10, 2006 8:36 pm ] |
Post subject: | |
no we were both wrong it wud be g2d.drawFill(x[], y[]); ![]() |