I have 2 lines and a point in space. I want to see which line the point is on. So a way to do this, is to get the distances from the point to each line and compare them. How to do that?
Also, how to get the coordinates of the intersection point of the green line and the black line?
Thanks

Hmmm search on google? What a nice and new idea! Wish I thought of that before coming here.
Well, if you did, you would have found things like this for example. You can adapt a lot of things from there. And if you only need this in the editor, you don’t have to adapt at all, just use these functions.
Thank you this is really helpful. And I did search on google A LOT and read many threads but didn’t find exactly what I was looking for.
I seem to have written this function before, you can refer to it
public static Vector3 NearestPoint(Line line, Vector3 pos)
{
var dotProduct1 = DotProduct((line.endpoint2 - line.endpoint1), (pos - line.endpoint1));
if (dotProduct1 <= 0) return line.endpoint1;
var dotProduct2 = DotProduct((line.endpoint1 - line.endpoint2), (pos - line.endpoint2));
if (dotProduct2 <= 0) return line.endpoint2;
var projection = dotProduct1 / line.Length;
return line.endpoint1 + (line.endpoint2 - line.endpoint1).normalized * projection;
}
public static float DotProduct(Vector3 v1, Vector3 v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
public class Line
{
public Vector3 endpoint1;
public Vector3 endpoint2;
public Line(Vector3 endpoint1, Vector3 endpoint2)
{
this.endpoint1 = endpoint1;
this.endpoint2 = endpoint2;
}
public float Length => (endpoint2 - endpoint1).magnitude;
}