# Nearest point to a z(x,y) function

Let's see if I can express my problem. I have created a grid mesh and then assigned to each (x,y) a z value (this is how I create z(x,y) function in animation nodes, I don't know if it's the best way). Now, this is a discrete function, I can't have a value of z(x,y) if that point doesn't belong to my grid mesh. What I want to know is if there is a way to obtain an aproximate value of z(x,y) for all the (x,y) inside the boundaries of my mesh (like you would have in an analytic function, in my case z=sin(x)). I assume that for creating the surface, Blender has to generate planes that join all the nearest vertices of the grid mesh, so getting the intersection with a vertical line that pass trough the point (x,y) that we want to evaluate (the orange one in the pictures) and those planes should be possible. • Does it need to be an AN solution or can it be python? And just to clarify, are you looking for the intersection point on a vertical line only? Apr 25, 2021 at 13:37
• A phyton script can work too! Yeah, at the end what I need is the intersection of a line with a mesh Apr 25, 2021 at 14:57
• What kind of output do you want? You could get all the XYZ values at once, with linear or smooth interpolation, using a shader, for output as an image. Apr 25, 2021 at 18:57

You can get an intersection using raycast BVH tree node. I have used your node set up and added an icosphere and an empty and have always execute option ticked in AN as shown. Just grab the empty and move it around. Make sure the always executing box is ticked so it updates when moving the empty. And if you want to find the point on the mesh nearest to the intersection just add these three nodes. If you move the empty below the mesh it will not work as the Ray Cast BVH Tree is just projecting downwards in -z direction from the empty. To solve that, tick the"Start in infinity" box in the Ray Cast BVH Tree node, it will then project in the opposite direction aswell.