Find a value of x-axis given a certain y-axis from a graph with a lineair line

Viewed 43

Consider the following graph:

enter image description here

We have on the y-axis an edge in millimeters (mm) and on the x-axis areas in (mm²).

We know these 4 values: For an area 60 000 mm² we have an edge of 60 mm and for 960 000 mm² we have an edge of 13 mm.

How to calculate in PHP for any value of the area, for example for 80 000 mm², the value of the equivalent edge?

1 Answers

Assuming there is a lineair correlation between edge an area like in your graph image, code below will calculate the edge for any given area.

The variable $certainArea can be used as input for any given area.

<?php
$edge1 = 60;
$edge2 = 13;
$area1 = 60000;
$area2 = 960000;

$inclination = ($area1 - $area2) / ($edge1 - $edge2);

$certainArea = 80000;

$edgeOfCertainArea = $edge1 - (($area1 - $certainArea) / $inclination);
Related