Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: converting double to pixel coordinates

  1. #1
    mkj is offline Member
    Join Date
    Jan 2012
    Rep Power

    Default converting double to pixel coordinates

    hi all,
    in my program i have a circle in a panel, that i want it to move0 on a parabola of equation y = ax2. in the circle class i have created a move method that moves that this circle using the repaint() method but the problem that i am having is that the filloval(int x, int y, int w, int h) does not accept double variables for x and y. for this reason my parabola trajectory is not so precise and the circle seems to jump instead of moving.
    i want to ask how can i make my circle move in smaller intervals to make it move instead of jumping.
    i was thinking of converting the double variables to pixel variables? does there exist any method that can do this
    thanks for any help.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: converting double to pixel coordinates

    converting the double variables to pixel variables?
    Can you give some examples of this?
    pixels are referenced by int values: 0 to width and 0 to height of the panel. There isn't a pixel at 4.345 There is a pixel at 4 and there is a pixel at 5.

    Look at the classes in the java.awt.geom package. Many of them take doubles are arguments.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: converting double to pixel coordinates

    All Graphics objects are instances of Graphics2D. You can cast the reference, apply suitable RenderingHints and draw or fill a Shape -- which may have subpixel coordinates.

    Have you gone through the 2D Graphics tutorial? For now you could start with Drawing Geometric Primitives (The Java™ Tutorials > 2D Graphics > Working with Geometry) but you should go through the whole tutorial trail as soon as you get the time.

    Norm likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 6
    Last Post: 11-02-2010, 04:14 PM
  2. Converting double to char array?
    By Blasz in forum New To Java
    Replies: 9
    Last Post: 08-29-2010, 07:32 PM
  3. NullPointerException converting String to double
    By infaddict in forum New To Java
    Replies: 3
    Last Post: 07-19-2008, 06:01 PM
  4. Converting String to Double
    By srini in forum New To Java
    Replies: 1
    Last Post: 12-24-2007, 08:03 PM
  5. Arc2D.Double coordinates
    By alley in forum Java 2D
    Replies: 2
    Last Post: 11-07-2007, 10:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts