Results 1 to 20 of 48
Thread: sine wave in java2D graphics.
 02062012, 10:10 AM #1Member
 Join Date
 Jan 2012
 Posts
 5
 Rep Power
 0
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....
 02062012, 01:47 PM #2
Re: sine wave in java2D graphics.
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)
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 02292012, 12:11 PM #3
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
 02292012, 01:24 PM #4
Re: sine wave in java2D graphics.
search in google for: java sinus graphics
 02292012, 01:27 PM #5
Re: sine wave in java2D graphics.
thx for the link

Re: sine wave in java2D graphics.
 02292012, 02:17 PM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,002
 Blog Entries
 7
 Rep Power
 20
Re: sine wave in java2D graphics.
Wat happened to your brains? For a set of points (x,y) in the domain D and codomain C where D is [Dmin, Dmax] and C is [Cmin, Cmax], the points can be scaled as follows: x'= (xDmin)/(DmaxDmin) and
y' = (yCmin)/(CmaxCmin); the points (x',y') are in the domain and codomain [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'*(SXmaxSXmin)+SXmin and Ys= y'*(SYmaxSYmin)+SYmin; the points (Xs,Ys) all are in the visible part of the window component.
kind regards,
Joscenosillicaphobia: the fear for an empty beer glass
 02292012, 03:12 PM #8Moderator
 Join Date
 Apr 2009
 Posts
 11,450
 Rep Power
 18
Re: sine wave in java2D graphics.
Ow.
You broke my brain...Please do not ask for code as refusal often offends.
 02292012, 03:25 PM #9
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,002
 Blog Entries
 7
 Rep Power
 20
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,
Joscenosillicaphobia: the fear for an empty beer glass
 03042012, 03:02 PM #10
 03042012, 03:29 PM #11
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,002
 Blog Entries
 7
 Rep Power
 20
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 codomain 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,
Joscenosillicaphobia: the fear for an empty beer glass
 03042012, 03:35 PM #12

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)Last edited by ozzyman; 03042012 at 03:49 PM.
 03042012, 03:48 PM #14
 03042012, 03:49 PM #15
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,002
 Blog Entries
 7
 Rep Power
 20

Re: sine wave in java2D graphics.
I added a link to the java doc.
 03042012, 03:52 PM #17
 03042012, 03:57 PM #18
 03042012, 04:11 PM #19
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,002
 Blog Entries
 7
 Rep Power
 20
 03042012, 04:16 PM #20
Similar Threads

Do number series represent sine wave?
By rng in forum New To JavaReplies: 12Last Post: 01182012, 03:46 PM 
sine and cosine
By Dennis in forum Advanced JavaReplies: 9Last Post: 11132010, 05:45 AM 
Java2D
By Alex j in forum Java 2DReplies: 1Last Post: 04072009, 04:59 PM 
Drawing the sine curve
By bumblyb33 in forum Java 2DReplies: 7Last Post: 03262009, 10:29 PM 
Demonstration of drawing points. It draws a sine wave
By Java Tip in forum SWTReplies: 0Last Post: 06282008, 09:25 PM
Bookmarks