7 Replies Latest reply on Dec 14, 2012 8:53 AM by 795605

# Help with understanding drawPolygon()

I have a triangle that I want to draw using drawPolygon(). This is what I have:
``````public void paint(Graphics g)
{
int[] xPoints =
{
30, 70, 40
};
int[] yPoints =
{
30, 30, 60
};
Polygon imageTriangle = new Polygon(xPoints, yPoints, 3);
g.drawPolygon(imageTriangle);
}``````
So this is what am understanding:

We have three points, (30, 30), (70, 30) and (40, 60), right?

From a cartesian plane, this will display an upright pyramid. But the actual program runs producing an upside-down odd shaped triangle.

Am I missing something? What do I need to do in order to display an upright pyramid?
• ###### 1. Re: Help with understanding drawPolygon()
Jamwa wrote:
From a cartesian plane, this will display an upright pyramid. But the actual program runs producing an upside-down odd shaped triangle.

Am I missing something? What do I need to do in order to display an upright pyramid?
You need to understand that the coordinate system isn't in the cartesian plane.
• ###### 2. Re: Help with understanding drawPolygon()
Understood. So what coordinate system does it follow?
• ###### 3. Re: Help with understanding drawPolygon()
Jamwa wrote:
Understood. So what coordinate system does it follow?
The standard computer graphics rastering system. Top left being 0, 0.
• ###### 4. Re: Help with understanding drawPolygon()
Then that makes sense as to why it appears upside down. Thanks
• ###### 5. Re: Help with understanding drawPolygon()
So when drawind a 4 sided polygon, what is the sequence?

I mean, why does
``````int[] xPoints =
{
70, 80, 80, 100
};
int[] yPoints =
{
80, 80, 100, 100
};

Polygon imageTriangle = new Polygon(xPoints, yPoints, 4);``````
Produce a polygon that the lines are crossing each other?
• ###### 6. Re: Help with understanding drawPolygon()
Because you're telling it to. The last point will be connected to the first point, since it'll always be a closed polygon.

Change the last xPoint to 70 and you'll have a square.
• ###### 7. Re: Help with understanding drawPolygon()
Thank you! Really appreciated