Drawing a polygon using doubles

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

  1. Rick

    Rick Guest

    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
    #1
    1. Advertising

  2. Rick

    Roedy Green Guest

    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.
    Roedy Green, Oct 8, 2003
    #2
    1. Advertising

  3. Rick

    Rick Guest

    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
    #3
  4. Rick

    Chris Smith Guest

    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
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    635
    Kevin Spencer
    Jan 9, 2006
  2. VisionSet
    Replies:
    8
    Views:
    2,077
    VisionSet
    Apr 28, 2004
  3. dan
    Replies:
    1
    Views:
    2,319
    Jack Klein
    Nov 26, 2003
  4. Dave Harris
    Replies:
    1
    Views:
    596
    Peter Otten
    May 28, 2004
  5. defn noob
    Replies:
    1
    Views:
    386
    Mark Space
    Jun 28, 2008
Loading...

Share This Page