CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

1. Junior Member
Join Date
Feb 2011
Posts
8

## A trigonometric plot

Heya, I've tried to make a program that plots a sinus curve.
The user is asked what width and scale he wants the plot to be.
The problem is that the scale is messed up and I would appreciate if someone could help me out
Code:
```public class Trigonometry {

public static void main(String[] args) {

double[] sinusarray = { 0.3, 0.7, 1, 1.3, 1.6, 1.9, 2.2, 2.5, 2.8, 3.1,
3.4, 3.7, 4, 4.3, 4.6, 4.9, 5.2, 5.5, 5.8, 6.1 };
sinus(sinusarray);
System.out.print("scale: ");

System.out.print("width: ");

plotFunctionstable(sinusarray, scale, width);
}

static void sinus(double[] array) {
for (int i = 0; i < array.length; i++) {
array[i] = Math.sin(array[i]) / array[i]; //

}

}

static void plotFunctionstable(double[] array, double width, double scale) {
for (int i = 0; i < array.length; i++) {
double blanksteg = scale * (width + array[i]);

for (int j = 0; j < blanksteg; j++) {
System.out.print(' ');
}
System.out.println('*');

}
}
}```
Last edited by Bertil; August 24th, 2011 at 01:06 PM.

2. Junior Member
Join Date
Aug 2011
Posts
10

## Re: A trigonometric plot

It seems to "work" in some sense.

Hard to tell without having a more clear idea of what you are trying to accomplish.

But this expression doesn't look exactly right to me: scale * (width + array[i])

3. Junior Member
Join Date
Aug 2011
Posts
10

## Re: A trigonometric plot

P.S. "sinus curve"?
This is the first time I've heard anyone use that word related to sin functions.

This is a sinus: http://www.krystalplonski.com/wp-con...sal-cavity.jpg

sinusoid and sinusoidal are more typically used.

(Sure; "sinus" is the original Latin word, but one doesn't usually expect Latin in that context. ;-)

#### Posting Permissions

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