@andrij.byelyayev I think I have a solution!
To review, given the following:
you would like to move and/or rotate Moving Part and have Tricky Part move and rotate accordingly. The rig should also work if the location of joint 3 on Tricky Part and joint 4 on Fixed Part are moved. In addition, Link 1-2, Tricky Part (2-5), link 5-6 and Moving Part (1-6) form a parallelogram linkage that ensures that the rotation of Tricky Part is the same as Moving Part.
Assuming that Joint 3 and 4 are temporarily fixed, we know that we can determine the location of joint3 if we know the angle that line 5-6 forms with a horizontal reference line. A valid solution will place joint3 a distance from joint4 that is equal to the length of line 3-4. I created a numerical method solution (i.e., a solver) to determine the angle of link 5-6.
The transform script for Tricky Part is:
The complete code is:
-- Calculate position and orientation of Tricky Part
-- that will have Joint3 a disatnce L34 from Joint4.
L56 = 228.35
L34 = 220
g1 = 0 -- lower limit angle guess L34 from Joint #4
g2 = 90 -- upper limit angle guess
gm = (g1 + g2)/2. -- mid angle guess
pt4 = Joint4pos * FixedPartT -- pivot point of link 3_4
m = copy MPT -- make independent copy of Moving Part's transform
for i = 1 to 10 do -- take 10 steps to converge to a solution
(
-- find the location of pivot point #3 for the 3 guesses
p1 = Joint8Pos * MPT + L56 * [cos(g1), 0 , sin(g1)]
p2 = Joint8Pos * MPT + L56 * [cos(g2), 0 , sin(g2)]
pm = Joint8Pos * MPT + L56 * [cos(gm), 0 , sin(gm)]
m.pos = p1
local v1 = Joint3Pos * m
m.pos = p2
v2 = Joint3Pos * m
m.pos = pm
vm = Joint3Pos * m
-- computer distances for the 3 guesses
d1 = length(pt4 - v1)
d2 = length(pt4 - v2)
dm = length(pt4 - vm)
if dm > L34 then -- determine which 2 guesses bracket solution
( g2 = gm
)
else
( g1 = gm
)
gm = (g1 + g2)/2. -- compute new middle guess value
i = i + 1
)-- end for ------
m.pos = pm
m -- position Trick Part to new location
The code works as follow. After the length of links 3-4 and 5-6 are defined, three initial guesses are made for the angle of link 5-6. They are g1 = 0Β°, g2 = 90Β° and midway guess gm = (g1 + g2)/2 = 45Β°.
The distance from joint 3 to joint4 for the three cases is then compared to the goal distance, the length of link 3-4. If the distance for angle gm is greater than link 3-4 (L34) then the upper bound is changed to gm (g2 = gm). if not, the lower bound is changed to gm (g1 = gm) and gm is redefine as the midway angle between the new set of g1 and g2. The process can be repeated until a desired level of precision is found. For now, I just limited the search to 10 iterations which works fairly well (I ran out of energy). I can adjust this later.
Once we know the location of Joint3 a LookAt contrainst is used to rotate link 3-4 and link 1-22 to their correct angles.
Note that joints 3 and 4 can be moved within their slots by simply changing to the local coordinate system and then moving these joints in the desired direction. Their position could of course be controlled by a Slider Manipulator.
There were many challenges in getting this solution.
- The original geometry behaved badly! I don't know why but my only solution was to rebuild the major parts.
- The were too many constraints already applied to objects. It's best to start with clean, unconstrained objects (e.g., no basic or inherit locks), IK constraints, etc.
- Poor choices for pivots. With links it is best to have a local principal axis that is in the direction of the link.
- I had the statement
m = MPTβ
in my code where MPT is the Transform matrix for Moving Part. Later in the code I modify the matrix m not realizing that in doing so MPT is also modified! I had assumed that, as with most other programming languages, modifying m does not affect MPT. I was wrong and discovered that m in this case was essentially an instance of MPT. This problem was fixed with the statement
m = copy MPTβ
Very simple once you know what to look for!
To see the action move and or rotate Moving Part in the attached file. The object could be linked to a path with follow checked and the part would move and rotate as the percent-along value is changed thus meeting your original goal. As noted, you can move joints 3 and 4.
lee.minardi