Results 1 to 3 of 3
- 02-05-2012, 01:32 PM #1Member
- Join Date
- Jan 2012
- Rep Power
converting double to pixel coordinates
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.
- 02-05-2012, 02:51 PM #2
Re: converting double to pixel coordinatesconverting the double variables to pixel variables?
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.
- 02-05-2012, 07:43 PM #3
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.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- By murdplacid in forum Java 2DReplies: 6Last Post: 11-02-2010, 05:14 PM
- By Blasz in forum New To JavaReplies: 9Last Post: 08-29-2010, 08:32 PM
- By infaddict in forum New To JavaReplies: 3Last Post: 07-19-2008, 07:01 PM
- By srini in forum New To JavaReplies: 1Last Post: 12-24-2007, 09:03 PM
- By alley in forum Java 2DReplies: 2Last Post: 11-07-2007, 11:27 PM