Skip to content

Commit cedbcc5

Browse files
committed
Let's try with the legancy function from ls 22..
1 parent 7fc0396 commit cedbcc5

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

scripts/specializations/CpShovelPositions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function CpShovelPositions:setShovelPosition(dt, shovelLimits, armLimits, height
417417
sy = yMin + 0.01
418418
ey = yMin + 0.01
419419
end
420-
local hasIntersection, i1z, i1y, i2z, i2y = MathUtil.getCircleLineIntersection(
420+
local hasIntersection, i1z, i1y, i2z, i2y = CpMathUtil.getCircleLineIntersection(
421421
az, ay, radiusArmToolToShovelTool,
422422
sz, sy, ez, ey)
423423

scripts/util/CpMathUtil.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,28 @@ end
319319
--- Divide a by b, but instead of throwing an error when b is 0, return math.huge
320320
function CpMathUtil.divide(a, b)
321321
return b == 0 and math.huge or a / b
322-
end
322+
end
323+
324+
--- Legancy function form LS22
325+
function CpMathUtil.getCircleLineIntersection(circleX, circleZ, radius, lineStartX, lineStartZ, lineEndX, lineEndZ)
326+
local p3x = lineStartX - circleX
327+
local p3z = lineStartZ - circleZ
328+
local p4x = lineEndX - circleX
329+
local p4z = lineEndZ - circleZ
330+
local m = (p4z - p3z) / (p4x - p3x)
331+
local b = p3z - m * p3x
332+
local dis = math.pow(radius, 2) * math.pow(m, 2) + math.pow(radius, 2) - math.pow(b, 2)
333+
334+
if dis < 0 then
335+
return false
336+
else
337+
local t1 = (-m * b + math.sqrt(dis)) / (math.pow(m, 2) + 1)
338+
local t2 = (-m * b - math.sqrt(dis)) / (math.pow(m, 2) + 1)
339+
local intersect1X = t1 + circleX
340+
local intersect1Z = m * t1 + b + circleZ
341+
local intersect2X = t2 + circleX
342+
local intersect2Z = m * t2 + b + circleZ
343+
344+
return true, intersect1X, intersect1Z, intersect2X, intersect2Z
345+
end
346+
end

0 commit comments

Comments
 (0)