2

I have a webcam camera situated on a laptop. It's world coordinates are (0,0,0). I have a person looking at the camera with a 3D position of the middle of their iris and a 3D gaze vector. I'm trying to cast a ray in the direction of the gaze vector, which intersects my plane (the screen of the laptop). My expected output is a coordinate which intersects the screen at z = 0.

I have tried implementing [https://stackoverflow.com/questions/5666222/3d-line-plane-intersection] (this) code (the numpy python answer) but I don't know how to define my plane or the plane normal.

import numpy as np
 
def LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint, epsilon=1e-6):
 
    ndotu = planeNormal.dot(rayDirection)
    if abs(ndotu) < epsilon:
        raise RuntimeError("no intersection or line is within plane")
 
    w = rayPoint - planePoint
    si = -planeNormal.dot(w) / ndotu
    Psi = w + si * rayDirection + planePoint
    return Psi

if __name__=="__main__":
    #Define screen length and width

    #Define plane
    planeNormal = np.array([0, 0, 1])
    planePoint = np.array([0, 0, 0]) #Any point on the plane
 
    #Define ray
    rayDirection = np.array([0.133757, 0.375544, -0.917102])
    rayOrigin = np.array([-3.6, -78.2, 393.2])
 
    Psi = LinePlaneCollision(planeNormal, planePoint, rayDirection, rayPoint)
    print ("intersection at", Psi)

Parameters

  • rayDirection = 3D Gaze vector
  • rayOrigin = Co-ordinates of Origin of ray
  • planeNormal = plane normal
  • planePoint = point on the plane
Robert H
  • 21
  • 1

0 Answers0