All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.finmath.plots.PlotableFunction2D Maven / Gradle / Ivy

Go to download

finmath lib plot extensions provide convenient plotting methods by providing consistent wrappers to plot libraries (like JFreeChart or JavaFX).

The newest version!
/*
 * (c) Copyright Christian P. Fries, Germany. Contact: [email protected].
 *
 * Created on 21 May 2018
 */
package net.finmath.plots;

import java.awt.BasicStroke;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import java.util.function.DoubleUnaryOperator;

public class PlotableFunction2D implements Plotable2D {

	private final double xmin, xmax;
	private final int numberOfPointsX;
	private final Named namedFunction;
	private final GraphStyle style;

	public PlotableFunction2D(final double xmin, final double xmax, final int numberOfPointsX, final Named namedFunction, final GraphStyle style) {
		super();
		this.xmin = xmin;
		this.xmax = xmax;
		this.numberOfPointsX = numberOfPointsX;
		this.namedFunction = namedFunction;
		this.style = style;

		if(numberOfPointsX < 2) {
			throw new IllegalArgumentException("Number of points needs to be larger than 1.");
		}
	}

	public PlotableFunction2D(final double xmin, final double xmax, final int numberOfPointsX, final Named namedFunction) {
		this(xmin, xmax, numberOfPointsX, namedFunction, new GraphStyle(new Rectangle(-2, -3, 5, 5), new BasicStroke(3.0f), null));
	}

	public PlotableFunction2D(double xmin, double xmax, int numberOfPointsX, DoubleUnaryOperator doubleUnaryOperator) {
		this(xmin, xmax, numberOfPointsX, new Named("", doubleUnaryOperator));
	}

	@Override
	public String getName() {
		return namedFunction.getName();
	}

	@Override
	public List getSeries() {
		final List series = new ArrayList();
		final DoubleUnaryOperator function = namedFunction.get();
		for(int i = 0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy