plotFunction

Fabian04088

Aktives Mitglied
/**
* This function plots the "functionToPlot" to the plottingArea using '.' as plotting character.
* The origin of the coordinate system of the function is at (xOrigin, yOrigin) within the plottingArea.
* It runs x from xStart to xEnd (both included), calculates y = functionToPlot(x) at each position and translates coordinates accordingly before plotting.
*
* @param xStart the start of the interval of integers for which we plot function values
* @param xEnd the end of the interval of integers for which we plot function values
* @param xOrigin x coordinate of the origin of the coordinate system in the plottingArea
* @param yOrigin y coordinate of the origin of the coordinate system in the plottingArea
*/
public static void plotFunction(int xStart, int xEnd, int xOrigin, int yOrigin) {
int height = plottingArea.length;

for(int i = xStart; i < xEnd; i++) {
int x = i + xOrigin;
int y = functionToPlot(x) + yOrigin;
FunctionPlotter.plotChar(x, y, '.');
FunctionPlotter.printPlottingArea();
}
}

was ist hier Falsch :(
 

AndiE

Top Contributor
Mir fehlt hier die Hälfte. Aber mal als Anhalt:

Gegeben ist eine Plotarea mit den Koordinaten x=(0 bis 79), und y=(0 bis 24) oder andere Werte.

In dieses Koordinatenfeld soll eine Funktion y=f(x) eingeschrieben werden, wobei der Wert von x zwischen(xmin und xmax) sein kann.

Offensichtlich muss man nun Delta x= xmax-xmin in 80 Teile teilen und für jeden Teil den y-Wert ausrechnen. Dann bestimmt man ymin und ymax und errechnet daraus die Koordinaten für die Punkte, die man dann ausgibt.

Soweit verstanden?
 

Neue Themen


Oben