Results 1 to 7 of 7
Thread: Double in drawLine()
- 03-20-2015, 07:14 AM #1
Member
- Join Date
- Feb 2015
- Posts
- 67
- Rep Power
- 0
Double in drawLine()
I am trying to make an applet that describes a predator and prey model and I came across a troublesome situation. I have extended Applet, now my problem is trying to draw a line that incorporates my numerical solution, but the problem is that drawLine() takes in only integer values but my numerical solution are doubles. The numerical solution interval is from 4.7 to 5.0. How can I get my draw line to take in doubles?
What I have imported, extended, and implemented is:
Java Code:import java.applet.*; import java.awt.*; import java.awt.event.*; public class PreyApplet extends Applet implements MouseListener, ActionListener, Runnable{ ... }
Java Code:public class Model { double[] prey = new double[1000]; double[] predator = new double[1000]; double[] dt = new double[101]; double[] b = new double[101]; prey[0] = 10; predator[0] = 5; dt[0] = 0; b[0] = 0.01; for (int j = 1; j < 101; j ++) { dt[j] = 2 + dt[j-1]; b[j] = b[0]*((double)j/2); } for(int i = 1; i < 100; i++) { prey[i] = prey[i-1] + (0.2*prey[i-1]*(1 - prey[i-1] / 500) -(b[i]*prey[i-1]*predator[i-1])/(1+b[i]*prey[i-1])) * (1/dt[i]); predator[i] = predator[i-1] + (0.1*predator[i-1]*(1-predator[i-1] /(0.2*prey[i-1])))*(1/dt[i]); //System.out.println("" + prey[i] + " " + predator[i]); } } }
- 03-20-2015, 07:45 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Double in drawLine()
drawLine() works with pixels (and so only ints make sense). One thing you could do is use a bigger scale. So for instance the range 4.7->5.0 could involve pixels 470->500.
- 03-20-2015, 08:12 AM #3
Member
- Join Date
- Feb 2015
- Posts
- 67
- Rep Power
- 0
- 03-20-2015, 08:32 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Re: Double in drawLine()
If the total range is 10.0045->10.00735 then could put the origin at 10 and use a 10,000x scale so the range goes from pixel 450 to pixel 735.
Where things get really tricky is where the range itself has four significant figures (where "significant" means you want to be able to distinguish on the monitor values that differ in the least significant place). In that case you have to buy a really big monitor...
More seriously, in that case you ought to think hard about the user interface and give the user the ability to scroll and zoom at will because you only have c1000 pixels on which to display the different values.
- 03-20-2015, 08:42 AM #5
Member
- Join Date
- Feb 2015
- Posts
- 67
- Rep Power
- 0
- 03-20-2015, 09:00 AM #6
Re: Double in drawLine()
Look up these classes/interfaces: Shape, Line2D.Double, Graphics2D, RenderingHints.
Since Java 1.1 or 1.2, all Graphics references are actually instances of Graphics2D, and can be cast as such. Simulation of sub-pixel resolution is achieved with RenderingHints.KEY_RENDERING / VALUE_ANTIALIAS_ON
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 03-20-2015, 09:01 AM #7
Similar Threads
-
drawLine - inconsistent endpoint
By buffalo in forum Advanced JavaReplies: 5Last Post: 04-27-2011, 02:43 AM -
problem with drawline using arrow key
By shazlin in forum New To JavaReplies: 1Last Post: 01-26-2011, 02:12 AM -
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 11:40 AM -
drawing ellipse by drawline method?
By hopey in forum Java 2DReplies: 8Last Post: 04-19-2009, 12:52 AM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 09:39 AM
Bookmarks