猫史档案馆


【box3代码】求两点之间最短距离

用户:翎with珝翎with珝查看:0 回复:4 评论:0 创建时间:2023-02-11T10:26:26


↓ ↓ ↓ 代码如下 ↓ ↓ ↓

//求出二维空间中两点之间最短距离
function two_Points_Away(x_start, y_start, x_end, y_end) {
    if (x_end > x_start && y_end > y_start) {
        return (Math.sqrt(Math.pow(y_end - y_start, 2) + Math.pow(x_end - x_start, 2)));
    } else if (x_start > x_end && y_end > y_start) {
        return (Math.sqrt(Math.pow(y_end - y_start, 2) + Math.pow(x_start - x_end, 2)));
    } else if (x_end > x_start && y_start > y_end) {
        return (Math.sqrt(Math.pow(y_s - y_end, 2) + Math.pow(x_start - x_end, 2)));
    } else if (x_start > x_end && y_start > y_end) {
        return (Math.sqrt(Math.pow(y_start - y_end, 2) + Math.pow(x_start - x_end, 2)));
    };
};

//实际示例
world.say(two_Points_Away(0, 13, 26, 72));

/*
 * 鸣谢名单
 * Mdn Wed Docx
 * https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math
 *
 * 神奇代码岛开发API
 * https://docs.box3.codemao.cn/js-tutorial.html#%E6%95%B0%E5%AD%A6
 * 
 * 函数说明
 * Math.sqrt(x)
 * 求x的平方根
 * 
 * Math.pow(x,y)
 * 求x的y次方
*/


回复

上一页1 页 / 共 1下一页
翎with珝翎with珝

第八行y_s改成y_start

点赞0


评论


FML饭米粒FML饭米粒

这个,,,

咋感觉,,,

没有必要呢()

虽然可以用来做个算法研究之类的()

但是()

感觉没啥实用性,,,

box3Vector3.distance就能搞定,,,

点赞1


评论


老6之六老6之六

要不要来我们工作室

点赞0


评论


小屑鹿小屑鹿

distance不香吗QwQ

点赞0


评论