Page 1 of 3 123 LastLast
Results 1 to 20 of 48
Like Tree14Likes

Thread: sine wave in java2D graphics.

  1. #1
    rbabu1988 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default 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....

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by rbabu1988 View Post
    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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Lightbulb 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

  4. #4
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default Re: sine wave in java2D graphics.

    search in google for: java sinus graphics

  5. #5
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    thx for the link

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by noobplus View Post
    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.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default 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
    Fubarable and ozzyman like this.
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: sine wave in java2D graphics.

    Ow.
    You broke my brain...
    Fubarable likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by JosAH View Post
    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
    Last edited by noobplus; 03-04-2012 at 04:20 PM.

  11. #11
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default 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
    noobplus likes this.
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by JosAH View Post
    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.)
    Last edited by noobplus; 03-04-2012 at 04:42 PM.

  13. #13
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default 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; 03-04-2012 at 04:49 PM.
    noobplus likes this.

  14. #14
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by ozzyman View Post
    I think you want the cubic one not the quadratic one?
    what is the coding for cubic one, bro
    regards

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by noobplus View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default Re: sine wave in java2D graphics.

    I added a link to the java doc.
    noobplus likes this.

  17. #17
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by JosAH View Post
    Do you think a quadratic parametric curve can approximate a sine wave?

    kind regards,

    Jos
    So shal i try CubicCurve2D instead

  18. #18
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by ozzyman View Post
    I added a link to the java doc.
    tyvm.. im trying the sine wave with cubicCurve2D.Double bro
    regards

  19. #19
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,786
    Blog Entries
    7
    Rep Power
    21

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by noobplus View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: sine wave in java2D graphics.

    Quote Originally Posted by JosAH View Post
    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

Page 1 of 3 123 LastLast

Similar Threads

  1. Do number series represent sine wave?
    By rng in forum New To Java
    Replies: 12
    Last Post: 01-18-2012, 04:46 PM
  2. sine and cosine
    By Dennis in forum Advanced Java
    Replies: 9
    Last Post: 11-13-2010, 06:45 AM
  3. Java2D
    By Alex j in forum Java 2D
    Replies: 1
    Last Post: 04-07-2009, 05:59 PM
  4. Drawing the sine curve
    By bumblyb33 in forum Java 2D
    Replies: 7
    Last Post: 03-26-2009, 11:29 PM
  5. Replies: 0
    Last Post: 06-28-2008, 10:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •