Sin(x) curve in java....

hi,does anybody know how to plot a sine (or a cosine)curve in an applet? Is there any library function available? Also, how to convert a float variable into an integer?
[189 byte] By [kravi76] at [2007-9-27 22:41:57]
# 1
As far as i know there is Math.sin at least in application, to converrt for example double to integer i usually use(int)value
GJavagirl at 2007-7-7 13:36:06 > top of Java-index,Archived Forums,Java Programming...
# 2

hi,

thanks...what packages i have to include to use Math.sin ..and how do i plot it in an applet?

Also...you said you will use (int)value for coverting double to integer? so you would use something like this? (int variable1)variable2?

where variable2 is double?

thanks again...

kravi76 at 2007-7-7 13:36:06 > top of Java-index,Archived Forums,Java Programming...
# 3
Hi, here is a part of the code when i transfer double to integerdouble table1=Double.parseDouble(s2);int f=(int)table;As for the libraries i suppose is java.util.*; or java.awt.event.*
GJavagirl at 2007-7-7 13:36:06 > top of Java-index,Archived Forums,Java Programming...
# 4
sorry mistake, you should write table instead of table1double table=Double.parseDouble(s2);int f=(int)table;
GJavagirl at 2007-7-7 13:36:07 > top of Java-index,Archived Forums,Java Programming...
# 5

You are going to want to override Applet's paint() method and put all your code in there. Become familiar with java.awt.graphics. Also, you are going to want to convert the function coordinates to the dimensions of your applet. The domain of the period of f(x)=sin x is [0,2*pi] and the range is [-1,1]. You are going to want the width of your applet to represent the domain and the height to represent the range. It's a simple multiplication and division trick. Just get some paper and work it out.

To convert a double to an integer you are going to cast it to an int. The cast will return an int value. Here's how it works.

double d = "123.456" ;

int i = (int) d ; // <- casts "d" to an int and returns, stores int in "i"

danperkins at 2007-7-7 13:36:07 > top of Java-index,Archived Forums,Java Programming...
# 6
I'm sorry, those quotes shouldn't be there.double d = 123.456 ;int i = (int) d ;
danperkins at 2007-7-7 13:36:07 > top of Java-index,Archived Forums,Java Programming...