Skip to content

Commit

Permalink
Let's try with the legancy function from ls 22..
Browse files Browse the repository at this point in the history
  • Loading branch information
schwiti6190 committed Dec 22, 2024
1 parent 7fc0396 commit cedbcc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/specializations/CpShovelPositions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function CpShovelPositions:setShovelPosition(dt, shovelLimits, armLimits, height
sy = yMin + 0.01
ey = yMin + 0.01
end
local hasIntersection, i1z, i1y, i2z, i2y = MathUtil.getCircleLineIntersection(
local hasIntersection, i1z, i1y, i2z, i2y = CpMathUtil.getCircleLineIntersection(
az, ay, radiusArmToolToShovelTool,
sz, sy, ez, ey)

Expand Down
26 changes: 25 additions & 1 deletion scripts/util/CpMathUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,28 @@ end
--- Divide a by b, but instead of throwing an error when b is 0, return math.huge
function CpMathUtil.divide(a, b)
return b == 0 and math.huge or a / b
end
end

--- Legancy function form LS22
function CpMathUtil.getCircleLineIntersection(circleX, circleZ, radius, lineStartX, lineStartZ, lineEndX, lineEndZ)
local p3x = lineStartX - circleX
local p3z = lineStartZ - circleZ
local p4x = lineEndX - circleX
local p4z = lineEndZ - circleZ
local m = (p4z - p3z) / (p4x - p3x)
local b = p3z - m * p3x
local dis = math.pow(radius, 2) * math.pow(m, 2) + math.pow(radius, 2) - math.pow(b, 2)

if dis < 0 then
return false
else
local t1 = (-m * b + math.sqrt(dis)) / (math.pow(m, 2) + 1)
local t2 = (-m * b - math.sqrt(dis)) / (math.pow(m, 2) + 1)
local intersect1X = t1 + circleX
local intersect1Z = m * t1 + b + circleZ
local intersect2X = t2 + circleX
local intersect2Z = m * t2 + b + circleZ

return true, intersect1X, intersect1Z, intersect2X, intersect2Z
end
end

0 comments on commit cedbcc5

Please sign in to comment.