Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Drawing a polygon using doubles (http://www.velocityreviews.com/forums/t127402-drawing-a-polygon-using-doubles.html)

Rick 10-07-2003 10:35 PM

Drawing a polygon using doubles
 
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


Roedy Green 10-07-2003 11:21 PM

Re: Drawing a polygon using doubles
 
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 10-08-2003 01:17 AM

Re: Drawing a polygon using doubles
 
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.



Chris Smith 10-08-2003 01:39 AM

Re: Drawing a polygon using doubles
 
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


All times are GMT. The time now is 10:45 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.