Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
我做的跳跃曲线计算函数(二次函数) - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


示例代码:

#include <easyx.h>
#include <math.h>

// 跳跃曲线计算函数
// x1, y1 二次函数和x轴的左侧交界点
// top_x, top_y 二次函数的顶点
// 返回关于x的二次函数中坐标x对应的坐标y
double jump_func(double x1, double y1, double top_x, double top_y, double x)
{
    /*
        函数解析式:y = a(x - top_x)^2 + top_y
        a = (y1 - top_y) / (x1 - top_x)^2

        所以 y = (y1 - top_y) / (x1 - top_x)^2 * (x - top_x)^2 + top_y
    */

    return (y1 - top_y) / pow(x1 - top_x, 2) * pow(x - top_x, 2) + top_y;
}

int main()
{
    initgraph(640,480);

    // 绘制一段二次函数
    for (int i = 0; i < 100; i++)
    {
        int y =
            (int)jump_func(
                0, 100,        // 与x轴的左侧交点
                50, 0,        // 函数顶点
                i            // 二次函数的参数
            );

        putpixel(i, y, WHITE);
    }

    // 在二次函数的三个点上画圆,确认二次函数没有问题
    circle(0, 100, 10);
    circle(100, 100, 10);
    circle(50, 0, 10);
    while(true);

    closegraph();
    return 0;
}


效果:

图片.png

非常完美。



返回首页


Copyright (C) 2018-2024 huidong