首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >指数函数算法

指数函数算法
EN

Stack Overflow用户
提问于 2014-09-17 19:12:14
回答 1查看 272关注 0票数 0

我需要实现一个从三个点插值指数曲线的函数,但我不知道该如何做。

我有一个图表,它的Y轴是百分比,0到100%,X是0到10。

我只知道(50,7),(100,10)和(0,0)。

我知道我可以创建一个数组,其中包含百分比和值,并循环它,但这并不是一种“正确”的方法。有没有更直接的算法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-17 19:17:01

我将使用公式

代码语言:javascript
复制
partial : total = % : 100
partial (the value) = (total * %) / 100

代码语言:javascript
复制
<?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);


?>

输出

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25898522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档