0

How to draw an image (of any type, png, jpg, bmp etc) of a Sine wave knowing frequency with amplitude = 1?

Example:

sine wave: amplitude over time

Laurel
  • 5,965
  • 14
  • 31
  • 57
Northumber
  • 315
  • 2
  • 3
  • 15

1 Answers1

1

One option is to use AndroidPlot. Firstly add it to your dependencies:

dependencies {
    compile "com.androidplot:androidplot-core:1.4.0"
}

Add an XYPlot to your layout and then start by amending the following example

More specifically have a look at:

   public Number getY(int series, int index) {
        if (index >= SAMPLE_SIZE) {
            throw new IllegalArgumentException();
        }
        double angle = (index + (phase))/FREQUENCY;
        double amp = sinAmp * Math.sin(angle);
        switch (series) {
            case SINE1:
                return amp;
            case SINE2:
                return -amp;
            default:
                throw new IllegalArgumentException();
        }
    }

And try changing sinAmp to your desired value.

ᴘᴀɴᴀʏɪᴏᴛɪs
  • 7,169
  • 9
  • 50
  • 81