How do you come up with a formula to calculate the yaxis base on the data given on the graph image below.
As you can see, the highest y value is 2, and the x value is 13.5 which is the middle point between 7 and 20.
-
What is the “y” axis when “x=10” ?
-
What is the “y” axis when “x=18” ?
Here’s my attempt to calculate the y-axis. It’s almost correct.
double xpoint = 9.0; //xpoint can be any number between 7 and 20
double ypos = 0.0;
double minx = 7.0;
double maxx = 20.0;
double maxy = 2.0;
double rangex = maxx - minx;
double middlex = rangex / 2;
double yunit = maxy / middlex;
double middlexTime = middlex + minx;
double yposAdjustment = 0.3;
if (xpoint > middlexTime) {
ypos = (maxx - xpoint).abs() * yunit + yposAdjustment;
} else {
ypos = (minx - xpoint).abs() * yunit + yposAdjustment;
}
2