Reputation: 517
I can't for the life of my wrap my head around this seemingly easy problem.
I am trying to create a sine wave with upper and lower bounds for the amplitude (ie. highest point is 3 and lowest point is 0.4)
Using regular math I am able to get a sine wave in an array from 1 to -1 but I don't know how to change those bounds.
static int MAX_POINTS = 100;
static int CYCLES = 1;
static double[] list = new double[100];
public static void SineCurve()
{
double phaseMultiplier = 2 * Math.PI * CYCLES / MAX_POINTS;
for (int i = 0; i < MAX_POINTS; i++)
{
double cycleX = i * phaseMultiplier;
double sineResult = Math.sin(cycleX);
list[i]= sineResult;
}
for(int i=0;i<list.length;i++){
System.out.println(list[i]);
}
}
Any tips would be greatly appreciated.
Upvotes: 0
Views: 1996
Reputation: 86774
The amplitude (multiplier of sin(x) value) is half the difference between the highest and lowest values you want. In your case
amplitude = (3 - 0.4)/2
which is 1.3
. Then zero offset is the lowest value plus the amplitude, which makes it 1.7
in your case.
The equation you want to graph is then
1.3 * sin(x) + 1.7
Upvotes: 3