简体   繁体   中英

How to create a sin wave with upper and lower amplitude bounds

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM