Search code examples
matlabvector3dcomputational-geometryangle

Find a point on a line perpendicular and through the middle of another line


In the diagram below

  • all points are in 3D space (x, y, z) and in the same plane
  • BC defines a vector with midpoint A
  • PA should be perpendicular to BC, however I do not know how to find P
  • I need to determine the angle between OA and PA

Do you know how this can be solved? Glad to provide additional info if needed.

enter image description here


Solution

  • It's a simple use of the cross-product and scalar-product:

    You first find a normal vector N of the plane spanned by those points. This is done via the cross product of B-A and O-A. Then the directional vector AP can be found as the cross product of N and B-A. For finding the angle we take the scalar product of the normalized vectors AP and AO, apply acos and convert to degrees.

    %// Example data
    A = [0,0,0];
    B = [-1,0,0];
    C = [1,0,0];
    O = [-1,-1,0];
    %// Computation
    normalize = @(X) X/norm(X);
    N = normalize(cross(B-A,O-A));
    AP = cross(N,B-A);
    phi = (180/pi)*acos(dot(normalize(AP),normalize(O-A)))