gpt4 book ai didi

像 actionscript 的 normalize(1) 一样工作的 Javascript 函数

转载 作者:搜寻专家 更新时间:2023-11-01 05:17:53 24 4
gpt4 key购买 nike

我需要一个返回 xy 点标准化数字的公式 - 类似于 actionscript 的 normalize() 函数。

var normal = {x:pt1.x-pt2.x,y:pt1.y-pt2.y};

normal = Normalize(1) // this I do not know how to implement in Javascript

最佳答案

我认为 as3 normalize函数只是缩放单位向量的一种方式:

function normalize(point, scale) {
var norm = Math.sqrt(point.x * point.x + point.y * point.y);
if (norm != 0) { // as3 return 0,0 for a point of zero length
point.x = scale * point.x / norm;
point.y = scale * point.y / norm;
}
}

关于像 actionscript 的 normalize(1) 一样工作的 Javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3592040/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com