Distance to Origin with Python I am calculating a 3d point on a face:



How can I get the distance to the origin from V1 either along the Y axis or along the face normal that I hit?

let me explain once more, I hope a bit more clear this time. I am shooting a ray with python, hitting a face (assume the direction is the face normal).



I want to find out the distance (d) of this normal from the face to the origin of the coordinate system.



But the face / plane could be anywhere, for example at the top, the bottom… and I want to find out the distance of this normal-vector of the face to the origin (0,0,0).

Thx for your help.
You could use this:  

bpy.context.scene.ray_cast(viewLayer, origin, direction)
viewLayer = the view layer you are operating on
origin = the Vector origin of the ray
direction = the normalised Vector direction 

If you are just using the default view layer you can just grab it via:
viewL = bpy.data.scenes['Scene'].view_layers["View Layer"]
origin would be the Vector position of V1
direction would be a normalised Vector, so (0,-1,0) for a negative Y axis direction

result = bpy.context.scene.ray_cast(viewL, (V1.x, V1.y, V1.z), (0,-1,0))  

result contains a tuple, with the second item containing the location of the hit point on the mesh  

So then you just want to calculate the distance between the two vectors so it would be:

import math

viewL = bpy.data.scenes['Scene'].view_layers["View Layer"]
result = bpy.context.scene.ray_cast(viewL, (V1.x, V1.y, V1.z), (0,-1,0))
hit = result[1]
distance = math.sqrt((V1.x - hit[0])² + (V1.y - hit[1])² + (V1.z - hit[2])²)