# Find perpendicular points to a line

I’m having a problem figuring out a way to find to points.

I’ve not moving objects around, but I’ve done so to illustrate the problem.

Position 1 (Pos1) is a cube.
Position 2 (Pos2) is an empty.

Together they form a line.

I’ve calculated a point perpendicular to this line and positioned an empty (Empty_perp1) at that point.
I’ve calculated another point perpendicular to this line and positioned an empty (Empty_perp2) at that point. This one is just the inverse vector of the first.

This is similar to a perpendicular bisector.

I’ve added a plane (circular) to show that the two empties lie in the same plane.

I’m trying to compute two additional points that lie in the same plane, but that are at 90 degrees from the first two points. These are labeled “Find” in the diagram.

I’m stumped.

Here is a diagram:

Here is the code:

``````        pos1 = bpy.data.objects['course_cube'].location
pos2 = bpy.data.objects['Empty_target'].location
obList = bpy.data.objects['Empty_perp1'], bpy.data.objects['Empty_perp2']

vect = mathutils.Vector()
vect = pos1.cross(pos2)
vect.normalize()

obList[0].location = pos1 + (.3 * vect)
obList[1].location = pos1 - (.3 * vect)

``````

Thanks

Subtract the cube’s position from the first empty’s position, and normalize this vector(yielding the directional vector from the cube to the empty). Subtract the position of the cube from the position of one of the secondary empties, and normalize this vector(yielding another direction).

Then, take the cross product of the two vectors above, and you’ll end up with a normalized directional vector that tells you the direction from the cube to the new empty. Optionally, multiply this new vector by the length of the distance you want the new empty to be from the cube, and then add it to the cube’s position. Now you’ve got the position of an empty perpendicular to the line, and at 90 degrees to the other two perpendicular empties. You can find the other empty’s position easily.

At least… I think that should work. let me know if it doesn’t.

You got it.
Thanks, it works perfectly.

Code:

``````
pos1 = bpy.data.objects['course_cube'].location
pos2 = bpy.data.objects['Empty_target'].location
obList = bpy.data.objects['Empty_perp1'], bpy.data.objects['Empty_perp2'], bpy.data.objects['Empty_perp3'], bpy.data.objects['Empty_perp4']

vect = mathutils.Vector()
vect = pos1.cross(pos2)
vect.normalize()

obList[0].location = pos1 + (.3 * vect)
obList[1].location = pos1 - (.3 * vect)

pos3 = pos2 - pos1
pos3.normalize()

pos4 = obList[0].location - pos1
pos4.normalize()

vect1 = mathutils.Vector()
vect1 = pos3.cross(pos4)
vect1.normalize()

obList[2].location = pos1 + (.3 * vect1)
obList[3].location = pos1 - (.3 * vect1)
``````