diff --git a/scripts/geometry/Vector.lua b/scripts/geometry/Vector.lua index 0daa77fcf..0429a9c70 100644 --- a/scripts/geometry/Vector.lua +++ b/scripts/geometry/Vector.lua @@ -160,12 +160,12 @@ end -- return the scalar projection of v on self ---@return number function Vector:scalarProjection(v) - return self:dot(v) / self:length() + return CpMathUtil.divide(self:dot(v), self:length()) end ---@return Vector function Vector:projection(v) - return (v:dot(self) / self:dot(self)) * self + return CpMathUtil.divide(v:dot(self), self:dot(self)) * self end ---@return Vector diff --git a/scripts/util/CpMathUtil.lua b/scripts/util/CpMathUtil.lua index ba1dc341f..e79f3d49d 100644 --- a/scripts/util/CpMathUtil.lua +++ b/scripts/util/CpMathUtil.lua @@ -7,8 +7,8 @@ function CpMathUtil.getIntersectionPoint(A1x, A1y, A2x, A2y, B1x, B1y, B2x, B2y) s2_y = B2y - B1y local s, t - s = (-s1_y * (A1x - B1x) + s1_x * (A1y - B1y)) / (-s2_x * s1_y + s1_x * s2_y) - t = ( s2_x * (A1y - B1y) - s2_y * (A1x - B1x)) / (-s2_x * s1_y + s1_x * s2_y) + s = CpMathUtil.divide(-s1_y * (A1x - B1x) + s1_x * (A1y - B1y), -s2_x * s1_y + s1_x * s2_y) + t = CpMathUtil.divide( s2_x * (A1y - B1y) - s2_y * (A1x - B1x), -s2_x * s1_y + s1_x * s2_y) if (s >= 0 and s <= 1 and t >= 0 and t <= 1) then --Collision detected