Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. The Burst compiler has its own forum section now.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Need to find a foot of a perpendicular on a line from a point in 3D.

Discussion in 'Scripting' started by 5c4r3cr0w, Aug 12, 2019.

  1. 5c4r3cr0w

    5c4r3cr0w

    Joined:
    Mar 8, 2016
    Posts:
    26
    Hello everyone,

    I guess I am stuck at this. I am trying to find a point (unknown) which is on a line and whose vector is perpendicular to another point (known). Here is a picture describing what I need to find out. Point P is an unknown point on green line and white sphere is a known projecting a perpendicular foot.

    Thanks
     

    Attached Files:

  2. 5c4r3cr0w

    5c4r3cr0w

    Joined:
    Mar 8, 2016
    Posts:
    26
    Ok, After banging my head on this problem for like two and half hours I finally came up with this solution. I am writing this down and adding an image for better understanding FootOfPerp.png if anyone get stuck in future.

    I got distance d from from the known point (white wiredsphere)from which green line originates (lets say point O). and got angle (-) which you can find by vector3.angle();

    so you get x distance by d/cos(-).
    and p will be O +x*OP.normalized;
     
unityunity