Function Plotting in Inkscape

Today I found myself needing to draw both a sine wave and a triangle wave accurately for a diagram in Inkscape. It turns out that all the required functionality is included, but you have to do a little work yourself. Here are my findings...

The tool is called Function Plotter and can be found under Effects | Render | Function Plotter...

Sine Wave

The sinusoid is easy to do.

Sine Wave Function Plotter configuration

  • Draw a rectangle with the rectangle tool, select it, then open the Function Plotter.
  • Check the "Multiply x-range by 2*pi" box so the end x-value represents how many periods you want.
  • Adjust the y values of the top and bottom of your rectangle---if your sine wave has a peak value of 1 and you want it to take up the whole box, use +/- 1 here.
  • Make sure that "use polar coordinates" is unchecked.
  • Choose enough sample points to get a good looking sine wave. It evaluates your function at various points and makes an interpolating path. In this case I got a reasonable looking sine-wave with only 8 samples.
  • Put "sin(x)" into the Function area and click Apply.

Your rectangle will turn into a sine wave, like this:

Sine WaveTriangle Wave

You can't make a triangle wave directly, but it can be built up from simpler functions.

Triangle Wave Function Plotter configuration

  • Draw a rectangle which will contain the triangle wave.
  • Set the end x-value to the total number of peaks you want.
  • Set the bottom y-value to 0.0 and the top y-value to 1.0.
  • Choose a large-ish number of samples. You'll probably want at least 25 per peak. This is necessary to get tight corners on your triangle wave because Inkscape tries to smooth out lines between your points.
  • Make sure that both the "multiply by 2*pi" and "use polar coordinates" options are unchecked.
  • Put "-2*fabs(fmod(x,1)-0.5)+1" into the Function area and click Apply.

Your rectangle will become a triangle wave like this one:

Triangle WaveConclusion

Inkscape's function plotter is very powerful for drawing paths conforming to shapes which you can define mathematically. The "Functions" tab in the Function Plotter gives a list of the available functions. Have a play with it.

Post a Comment

Your email is never shared.