Move/rotate a line segment intersecting another, just enough so that they become orthogonal

geometrytrigonometryvectors

I'm trying to find a way to move or rotate a line segment intersecting another until they become orthogonal (the angle formed in the intersection is tuned into 90 degrees) while keeping the length of the line and the intersection point intact, a sample problem is displayed in the image below:

Sample problem

### Sample lines:
lineA = ([2, 4], [1, 1])
lineB = ([1, 1], [4, 1])
# Intersection point: (1,1)

In the sample our target would be the point "a1". Keep in mind while the angle in the sample above is less than 90 degrees there may be cases in which the angle may be more than 90. To make the problem simpler, suppose we know from before hand which line we need to modify (for the sample above, line "a").

I know how to calculate the angle between the lines but don't know where to go from here.

Appreciate your help.

P.S: Sorry for not making the image inline! I'm new here and one needs 15 points to be able to paste inline images.

Best Answer

You could calculate a transformation of your coordinate system that rotates lineA around it second endpoint until it is orthogonal to lineB.

A simpler approach is: the transformation will preserve the length of lineA and the position of one endpoint, but will wipe out other properties, such as the original direction of the line segment. But the transformation must also add a property, that the transformed segment is orthogonal to lineB. So instead of computing the transformation, we simply build the result with the known properties it must have:

  1. Identify the common endpoint of lineA and lineB, call it $b_1$.
  2. Identify the line through $b_1$ orthogonal to lineB.
  3. Construct a line segment lying on the line in step 2, with one endpoint at $b_1$, the other endpoint at a distance from $b_1$ equal to the length of lineA.

In coordinates, the direction of lineB is represented by the vector $[4,1] - [1,1] = [3,0],$ and an orthogonal line has the direction given by a vector orthogonal to $[3,0].$ To find a vector orthogonal to $[x,y]$ we can take $[-y,x]$ or any non-zero multiple of $[-y,x]$, including $[y,-x]$. So let's take $[0,3]$ as the vector orthogonal to $[3,0].$

We need the vector from $b_1$ to the other endpoint of the new segment to have the same length as lineA, which is $\sqrt{(2-1)^2 + (4-1)^2} = \sqrt{10}.$ So we multiply $[0,3]$ (which has length $3$) by $\frac{\sqrt{10}}{3}$ to obtain a vector of length $\sqrt{10}$ in the same direction: $[0, \sqrt{10}].$ (Actually in this example we could have seen directly that the answer would be $[0, \sqrt{10}]$ without working out the multiplication factor, but the method used here will also work in the case where lineB is not parallel to a coordinate axis, when it is not so obvious how to substitute coordinates to obtain the desired length in the same direction.)

Finally we find the other endpoint of the new segment by adding the vector we just found to the coordinates of the known endpoint, $b_1$:

$$ [1,1] + [0, \sqrt{10}] = [1, 1 + \sqrt{10}] . $$

The rotated copy of lineA is therefore $([1,1], [1, 1 + \sqrt{10}]).$

There is one more detail you might like to enforce: to choose which of the two possible answers to produce. There are, after all, two places you could rotate lineA to so that it is orthogonal to lineB, one on each side of lineB. If you want to minimize the amount of rotation you want to choose the answer on the same side of lineB as the original lineA.

To get the other possible result in this example, instead of simply adding $[1, 1 + \sqrt{10}]$ to $b_1$ we multiply by $-1$ first and then add; or equivalently, we simply subtract $[1, 1 + \sqrt{10}]$, with the result

$$ [1,1] - [0, \sqrt{10}] = [1, 1 - \sqrt{10}] . $$

If you are doing this graphically, you can eyeball the directions of lineB, lineA, and the vector you find orthogonal to lineB, and choose to add or subtract that vector according to whichever way produces a segment on the same side of lineB as lineA.

If you are doing this numerically without the aid of graphics and a human eye (for example writing a simple computer program to solve the problem), you first find a vector of the correct length orthogonal to lineB, which vector may be in the correct direction or the opposite direction. Then you can use the "dot" product of this vector with the vector from $a_2$ to $a_1$ to decide whether to add or subtract. If the "dot" product is positive then the angle between vectors is less than $90$ degrees and you should add the new vector to $b_1,$ but if the "dot" product is negative than the angle is greater than $90$ degrees and you really want the "other" orthogonal vector, so you should subtract.

Related Question