Solved

Drawing sinusoidal wave

Posted on 1998-12-18
1
1,026 Views
Last Modified: 2008-03-10
Hi all again!! do you have a function which draws a sin wave using the sin method of Math class? Or at least, can you guide me in programming that function by myself?

Thanks a lot in advance
jstuardo@aclaris.cl
0
Comment
Question by:skel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
malexiev earned 50 total points
ID: 1229731
Try this:

  import java.awt.*;  
  import java.applet.*;
 
  public class Test
  extends Applet {  
   
    private final double scale = 50;
    private double step = 1 / scale;
   
    public Test() {
    }    
   
    public void drawSin(Graphics g, double x0, double x1) {
     
      g.setColor(Color.red);      
      int i = 0;      
      int y0 = getBounds().height >> 1;
      for (double f = x0; f < x1; f += step,i++) {
        g.drawLine(i, (int)((Math.sin(f)) * scale + y0),
                   i, (int)((Math.sin(f)) * scale + y0));
       
      }
    }
   
    public void paint(Graphics g) {
      drawSin(g, -Math.PI, Math.PI);
    }
  }

Hope this helps.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 41
Java: The Public Class Main 4 45
Notify sent to other threads in Java 9 43
DTD and JAVA versions 1 33
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question