# Cast Ray Through a Point

Hello, I trying to cast a ray through a point (specifically the 3D cursor). I am using scene.ray_cast(), but I need the start (which I have) and the end (a point beyond the 3D cursor). How could I find the end point of a line segment beginning at my start point, passing through the 3D cursor, and then terminating a set distance from the 3D cursor. I could probably figure out a more complicated way to calculate this, but I would think there’s a simpler way with the Vector class. Thank you for any help!

Edit: figured it out, message me if you want to know how.

Someone requested I post my solution, so here it is:

import bpy
from mathutils import Vector

start = [0.0,0.0,0.0]                                        #set this to whatever point you want to cast the ray from
end = [1.0,1.0,1.0]                                         #set this to whatever point you want to cast the ray through
distance = 1                                          #distance beyond the end you want to cast. If it's negative the ray will end before the end point
line = Vector(end) - Vector(start)               #get the vector between the two points
line = line.normalized()                               #change the vector to length 1
line = line*distance                                      #make the vector how long we want it
new_end = Vector(end) + line                   #add the vectors to find our new end point
ray = bpy.context.scene(start, new_end)   #cast the ray

I haven’t tested this exact code, I just copied the relevant parts from my own code, but this should be correct. If you have any questions feel free to ask.