sine wave in java2D graphics.

Hi i m new to Java 2D. i want to draw a sine wave based on the given frequency and amplitude of user input. Pls can anybody help me how to draw sine wave using 2D. i ve tried many sites , but i found only the programs which draws the sine wave based on the default height and width of the frame.Pls help me...

Thanks in advance....

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**rbabu1988** i ve tried many sites , but i found only the programs which draws the sine wave based on the default height and width of the frame.

Sounds like you're trying to build the top floor of a building without anything under it, not even a foundation.

Learn Java Graphics.

Trail: 2D Graphics (The Java™ Tutorials)

Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

db

Re: sine wave in java2D graphics.

hi,

I need to write a sine wave program for my project work of my final year engineering

Could you give me a sine wave program which can draw sine waves for given values, my sample value file is a ".dat" format with 10,000 values of x an y in two fields.

thanks in advance:coffee::(angel)::beer:

Re: sine wave in java2D graphics.

search in google for: java sinus graphics

Re: sine wave in java2D graphics.

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**noobplus** I need to write a sine wave program for my project work of my final year engineering

Could you give me a sine wave program which can draw sine waves for given values, my sample value file is a ".dat" format with 10,000 values of x an y in two fields.

No. If you're looking for the do my work for me and give me a program forum, this isn't it. We will be more than happy to help you with **your own program and your code**, but we are not hear to do your work for you or to help you cheat.

Re: sine wave in java2D graphics.

Wat happened to your brains? For a set of points (x,y) in the domain D and co-domain C where D is [Dmin, Dmax] and C is [Cmin, Cmax], the points can be scaled as follows: x'= (x-Dmin)/(Dmax-Dmin) and

y' = (y-Cmin)/(Cmax-Cmin); the points (x',y') are in the domain and co-domain [0, 1]. If a window component has the ranges [SXmin, SXmax] and [SYmin, SYmax] the points (x',y') can be scaled to those ranges:

Xs=x'*(SXmax-SXmin)+SXmin and Ys= y'*(SYmax-SYmin)+SYmin; the points (Xs,Ys) all are in the visible part of the window component.

kind regards,

Jos

Re: sine wave in java2D graphics.

Ow.

You broke my brain...

Re: sine wave in java2D graphics.

Oh dear; just for the record: the explanation is much longer than the code itself. Are computer folks allergic to a bit of math? It doesn't bite and can be quite useful most of the time (see this entire thread for a silly example).

kind regards,

Jos

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**JosAH** Wat happened to your brains? For a set of points (x,y) in the domain D and co-domain C where D is [Dmin, Dmax] and C is [Cmin, Cmax], the points can be scaled as follows: x'= (x-Dmin)/(Dmax-Dmin) and

y' = (y-Cmin)/(Cmax-Cmin); the points (x',y') are in the domain and co-domain [0, 1]. If a window component has the ranges [SXmin, SXmax] and [SYmin, SYmax] the points (x',y') can be scaled to those ranges:

Xs=x'*(SXmax-SXmin)+SXmin and Ys= y'*(SYmax-SYmin)+SYmin; the points (Xs,Ys) all are in the visible part of the window component.

kind regards,

Jos

hi thnx and what is "C" and "D" , I knew well that the two columns u took them as x and y

regards

Re: sine wave in java2D graphics.

If you want to plot/draw, say, f(x) = sin(x) for a single period the the domain D is the range [0, 2*pi] and the co-domain is the interval [-1, 1]; all points x, y are in the intervals DxC. My previous reply showed how to scale those values to other intervals (e.g. screen coordinates).

kind regards,

Jos

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**JosAH** If you want to plot/draw, say, f(x) = sin(x) for a single period the the domain D is the range [0, 2*pi] and the co-domain is the interval [-1, 1]; all points x, y are in the intervals DxC. My previous reply showed how to scale those values to other intervals (e.g. screen coordinates).

kind regards,

Jos

hi,

does *g2.draw(new QuadCurve2D.Double(xx,xx,X,midX,Y,midY);* work for drawing vs x and y values

(i dont know, i think, "xx,xx" must be the domain range.)

Re: sine wave in java2D graphics.

I think you want the cubic one not the quadratic one?

CubicCurve2D.Double (Java 2 Platform SE v1.4.2)

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**ozzyman** I think you want the cubic one not the quadratic one?

what is the coding for cubic one, bro

regards

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**noobplus** hi,

does *g2.draw(new QuadCurve2D.Double(xx,xx,X,midX,Y,midY);* work for drawing vs x and y values

(i dont know, i think, "xx,xx" must be the domain range.)

Do you think a quadratic parametric curve can approximate a sine wave?

kind regards,

Jos

Re: sine wave in java2D graphics.

I added a link to the java doc.

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**JosAH** Do you think a quadratic parametric curve can approximate a sine wave?

kind regards,

Jos

So shal i try CubicCurve2D instead

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**ozzyman** I added a link to the java doc.

tyvm.. im trying the sine wave with cubicCurve2D.Double bro

regards

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**noobplus** So shal i try CubicCurve2D instead

Do you know what those curves are? Do you know what Bezier curves are? Do you think a Bezier curve can model a sine wave?

kind regards,

Jos

Re: sine wave in java2D graphics.

Quote:

Originally Posted by

**JosAH** Do you know what those curves are? Do you know what Bezier curves are? Do you think a Bezier curve can model a sine wave?

kind regards,

Jos

would u mind explaining the curves plz.. it is necessary for my project works . im doing my final year project and last date is next monday