# Drawing a polygon using doubles

Discussion in 'Java' started by Rick, Oct 7, 2003.

1. ### RickGuest

Hi,

There's a method called drawPolygon in the java.awt.Graphics class which
takes in two integer arrays for drawing a polygon. Is there someway I
could draw a polygon using two arrays of doubles? If I convert my double
values to integer, I get an incorrect figure. Thanks

Rick

Rick, Oct 7, 2003

2. ### Roedy GreenGuest

On Wed, 08 Oct 2003 08:35:09 +1000, Rick <rrquick@nospam-com> wrote or
quoted :

>If I convert my double
>values to integer, I get an incorrect figure. Thanks

You are going to have to scale and round your doubles to int pixels.

See http://mindprod.com/convert.html

For another way to draw a polygon, see
http://mindprod.com/jgloss/polygon.html

--
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Roedy Green, Oct 8, 2003

3. ### RickGuest

Thanks Roedy, that helped.

Roedy Green wrote:
> On Wed, 08 Oct 2003 08:35:09 +1000, Rick <rrquick@nospam-com> wrote or
> quoted :
>
>
>>If I convert my double
>>values to integer, I get an incorrect figure. Thanks

>
>
> You are going to have to scale and round your doubles to int pixels.
>
> See http://mindprod.com/convert.html
>
> For another way to draw a polygon, see
> http://mindprod.com/jgloss/polygon.html
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Rick, Oct 8, 2003
4. ### Chris SmithGuest

Rick wrote:
> There's a method called drawPolygon in the java.awt.Graphics class which
> takes in two integer arrays for drawing a polygon. Is there someway I
> could draw a polygon using two arrays of doubles? If I convert my double
> values to integer, I get an incorrect figure. Thanks

You could cast your Graphics to a Graphics2D, then use draw(Shape)
providing a GeneralPath constructed of Line2D.Double objects. That
would definitely do it.

On the other hand, when you say "If I convert my double values to
integer, I get an incorrect figure", I start to wonder. Double values
would be useful for anti-aliasing to get the appearance of a better
polygon, but beyond that, the greatest precision that the screen has is
a pixel anyway, so you'd better not be getting anything too awfully
"incorrect", or a double version isn't going to fix it.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Chris Smith, Oct 8, 2003