# constraining an empty to the intersection of two coplanar segments

For some reason I have two coplanar segments (each represented by a 2 points path), moving relative to each other in a way that guarantees they are always intersecting.

What I would like is to constraint an empty to follow the intersection of these segments.

The movement of the intersection point is far too complicated to be plotted manually or analytically, especially since the idea is to try various configurations that will change the position and rotation of these segments.

I tried using constraints, a combination of "damped track" and "clamp to" (i.e. orienting one axis of the empty parallel to the segment first, and clamping according to this axis next), but to no avail.
I get the empty to follow the first path in the constraint stack, but though it moves somewhat close to the second path, it remains quite far from the intersection.

Maybe the whole idea of using constraints is wrong? I'm interested in any trick that would make this work, including python scripting if there is no other way (I suppose a scripted driver could easily compute the intersection coordinates, but I would hate to hard-code object references and such).

EDIT:
this cross-question discussion is kinda awkward, but here is a modified version of the proposed answer : I just moved the end of the rod to reflect the fact that it is not aligned to any global axis. This is a major constraint that had me conclude an analytic solution was too complex to code as a driver formula. Another constraint is that the slot inside the crank must be a straight line. This piece is supposed to be cut out by hand from a few mm of plywood, and trying to carve out a complex elliptic curve is out of the question (you would never manage to get the precision without laser cutting).

I have no doubt the trigonometry of your model is correct, and the precision is more than enough. Still, it makes the hypothesis that the rod axis of rotation is aligned with global X, and the contact point describes some complex trigonometric curve (I suspect it would be more like some Lissajou curve than a mere part of ellipsis if the axis was not aligned with global X, but not a straight line anyway).

As soon as its axis deviates from X, you can see the end of the rod going round in cicles as the crank moves. In what I try to simulate, the axis should remain stable and the "top" empty should slide along the crank radius to allow the rod to rotate without shifting position or deforming.

Maybe some formula adjustment can fix this, but I can't see how. At the very least the formula should take the rod rotation axis into account, which would probably require an arcsine of the two axis cross product.

• I believe that drivers is your answer, but can you elaborate on your path setup just a little? Is it effectively two lines/edges that could be calculated using a slope intercept formula? – Rick Riggs Mar 2 '16 at 3:11
• This question is an attempt to approximate the solution of this problem. If a driver is the answer, I suppose it's better to make it compute the cone-line intersection that would solve the problem entirely. – kuroi neko Mar 2 '16 at 3:45
• After looking at this post, I can't help but ask for clarification's sake, are you primarily needing to calculate the point at which the rod rotation @ '5' slides through '4' when '3' is rotated, thus giving you the rotation of '5' by known rotation of '3'? – Rick Riggs Mar 2 '16 at 6:31
• yes, exactly. The idea is to rotate the servo arm and have the gig follow, up to the aileron itself (which will rotate around the axis according to move '5') – kuroi neko Mar 2 '16 at 8:28

I'm going to post what it is that I believe you are looking for.

If it is wrong, I can always come back and delete the answer. What I did was add two empties:

1. The 'Base' located to the center of rotation of the rod which also has the driver on the y rotation.

AND

1. The 'Top' which is parented to the z-rotation arm.

THEN

solved the triangle with a simple trig function using the view plane of X/Z.

You just need to know the absolute difference between the 'basex' & 'topx' locations for the 'X-axis' for the horizontal leg of the triangle, then get the absolute distance for the 'basez' & 'topz' locations for the 'Z-axis' for the vertical leg, and use the 'atan' function to get the angle of this relationship.

So I ended up with these four variables in the driver:

basex, topx, basez, topz

and I used this as the expression:

atan( (abs(basex - topx)*1.0000000000) / (abs(basez - topz)*1.0000000000) )

The reason for using the '1.0000000000' value was to force the calculation to be multiplied at this many decimal places for rotational accuracy.

Here's the Blend File: NOTE:

1. Select the rotational arm and rotate about 'Z' to see the effect.

2. Select the rod to see the driver in the graph editor

3. For some reason, the driver value can get stuck and not update the solution before the frame updates so maybe reducing the Multiply by 1.0000000000 to 1.0000 is good enough in this case as it should really decrease the effort of calculation. After doing this, and making the hole of the crank more fitting for the bent rod to twist and elongate elliptically, I was able to get a much better solve with the same logic. • Thanks a lot for your answer. I came up with an equivalent approximation using the "Top" empty parented to the crank and an IK chain anchored to the rod. Unfortunately, this solution does not mimic reality. The "Top" empty represents the contact point between the rod and the crank, and in reality it moves along the slot (i.e.it is not in a fixed position relative to the crank). Looking closely at your gig, one can see the rod deform during movement (i.e. the length and angle of the last rod segment vary). Nevertheless, this is an elegant approximation. – kuroi neko Mar 2 '16 at 8:38
• Please see the Notes for an update regarding inaccuracies. Specifically #3 and the number of decimals used. – Rick Riggs Mar 2 '16 at 9:52
• I looked at your example the best I could, but it still does not seem to match what I want. See my edit for details. – kuroi neko Mar 2 '16 at 10:29

My own solution:

I never managed to make blender position an empty at the intersection of two paths. I suspect the slightest rounding error is enough to kick the constrained object out of the plane shared by the two paths, so that the second constraint works on a position that cannot be moved along the second path.

However, I did manage to place an object on the intersection of a plane and a path, using a combination of "clamp to" and "floor".

The idea is to replace one of the segments with a plane that contains it.
The "floor" constraint uses the object center and one of the local orientation vectors (if you check the "use rotation" option), so to provide a suitable "plane" you can align one of the local vectors with the segment, make sure the object origin passes through the segment(setting origin to center of mass for instance), and pick any of the two other local vectors as the normal the "floor" constraint will work with.

You must position the constrained object on one side of the plane, so that you can choose the sign of the normal used by the "floor" constraint.

Lastly, you should put the "floor" constraint above the "clamp to" in the stack.

I got pretty good results, though I noticed some slight deviations from the intersection plane.