我需要实现一个从三个点插值指数曲线的函数,但我不知道该如何做。
我有一个图表,它的Y轴是百分比,0到100%,X是0到10。
我只知道(50,7),(100,10)和(0,0)。
我知道我可以创建一个数组,其中包含百分比和值,并循环它,但这并不是一种“正确”的方法。有没有更直接的算法?
发布于 2014-09-17 19:17:01
我将使用公式:
partial : total = % : 100
partial (the value) = (total * %) / 100码
<?php
$points = array("8%,67%","36%,74%","73%,13%");
function return_value($percentage,$total) {
$value = ($total * $percentage) / 100.0;
return $value;
}
function evaluate_points($points) {
$max_x = 100.0; // As float value
$max_y = 10.0; // As float value
for ($point = 0; $point < count($points); $point++) {
//Replace the % sign
$points[$point] = str_replace("%", "", $points[$point]);
$point_percentages = explode(",", $points[$point]);
$x_percentage = $point_percentages[0];
$y_percentage = $point_percentages[1];
echo("The value for x is : ".return_value($x_percentage,$max_x) ."<br>");
echo("The value for y is : ".return_value($y_percentage,$max_y). "<br><br>");
}
}
evaluate_points($points);
?>输出

https://stackoverflow.com/questions/25898522
复制相似问题