Getting a 3D position from mouse click. Makie.jl

I’ve done a bunch of this mouseposition to ray to intersection point business for DataInspector. All of the code for that is currently here: https://github.com/JuliaPlots/Makie.jl/blob/master/src/interaction/inspector.jl

view_ray(scene) will give you an (origin, ray_direction) in 3d space. There’s also closest_point_on_line which returns a point on a line (between A and B) and ray_triangle_intersection which returns a point on a triangle. I also have some code to find a point on the ray closest to another point which I haven’t pushed yet:

function relative_inverse_project(scene, pos)
    origin, dir = view_ray(scene)
    relative_inverse_project(pos, origin, dir)
end
function relative_inverse_project(pos, origin, dir)
    # This solves the following triangle:
    # pos ------ output
    #      \   |
    #       \  |
    #        \ | ↑ dir
    #         \|
    #        origin
    # where pos is the position of some anchor point and 
    # origin, dir define a ray (with dir assumed to be normalized)
    origin .+ sqrt(norm(pos .- origin) - dot(pos .- origin, dir)) * dir
end

Maybe some of those will be helpful.

3 Likes