- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created the following code to calculate the location of the end of a boom from a bus (trolley) to an overhead cable.
-- positions PointCable on line001 a distance LabelControl
-- from PointBus
-- v .01 2/6/2022 L. Minardi
clearlistener()
fn CalculateCablePoint =
(
select $line001
cable = $
select $PointCable
pCable = $
sM = [0,0,0]
global delta = 0.1
global s = delta
global L= 20.
select $Bus
BusT = $.transform
select $PointBus
pBus = $.position
sA = 0.0 -- % along value for A
sB = delta -- initial % along guess for B
flag = true
pA = interpCurve3D cable 1 sA -- point A
pB = interpCurve3D cable 1 sB -- point B
dA = distance pBus pA
dB = distance pBus pB
-- get to intervale containing solution
for i = 1 to 10 while flag do
(if dB > L then
(
pA = pB
sA = sB
sB = sB + delta
pB = interpCurve3D cable 1 sB
dB = distance pBus pB
)
else
( flag = false
)
)
-- interval found, now iterate between A and B
flag = true
for i = 1 to 5 while flag do
(
sM = (sA + sB)/2.
pM = interpCurve3D cable 1 sM
dM = distance pBus pM
err = abs(dm - L)
if (err < (0.01 * L)) then
( flag = false
format ("i = %, error = % ") i err
)
if dM < L then
(
pB = pM
sB = sM
)
else
(
pA = pM
sA = sM
)
) -- end for
pCable.pos = pM
)
CalculateCablePoint()
It works for a single location of the bus. I am trying to enhance it to generate keyframes as the bus moves. I have tried adding a For loop for the entire program and then the following statements to create keyframes at the end of the code. Note, pM is the point location of for the point object PointCable which the boom references with a LookAT constraint.
select $PointCable
pCable = $
slidertime = j
with animate on
pCable.pos = pM
The keyframes are created but they are all the location and do not track along the cable as the bus moves. Here's the version with the loop. Any suggestion as to how to get it to generate keyframes for each calculation of pM?
-- positions PointCable on line001 a distance LabelControl
-- from PointBus
-- v .02 2/7/2022 L. Minardi
clearlistener()
clearSelection
--fn cp =
--(
--with animate on
for j = 1 to 15 do
(
select $line001
cable = $
select $PointCable
pCable = $
sM = [0,0,0]
global delta = 0.1
global s = delta
global L= 20.
select $Bus
BusT = $.transform
select $PointBus
pBus = $.position
sA = 0.0
sB = delta
flag = true
pA = interpCurve3D cable 1 sA
pB = interpCurve3D cable 1 sB
dA = distance pBus pA
dB = distance pBus pB
-- get to intervale containing solution
for i = 1 to 10 while flag do
(if dB > L then
(
pA = pB
sA = sB
sB = sB + delta
pB = interpCurve3D cable 1 sB
dB = distance pBus pB
)
else
( flag = false
)
)
-- now iterate between A and B
flag = true
for i = 1 to 5 while flag do
(
sM = (sA + sB)/2.
pM = interpCurve3D cable 1 sM
dM = distance pBus pM
err = abs(dm - L)
if (err < (0.01 * L)) then
( flag = false
format ("i = %, error = % ") i err
)
if dM < L then
(
pB = pM
sB = sM
)
else
(
pA = pM
sA = sM
)
) -- end for
pCable.pos = pM
clearselection()
select $PointCable
pCable = $
slidertime = j
with animate on
pCable.pos = pM
) -- end for j
Solved! Go to Solution.