?
Solved

Drawing sinusoidal wave

Posted on 1998-12-18
1
Medium Priority
?
1,031 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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 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