# Using ofxRay to determine plane intersection

Hi all,
I am using ofxHeadPoseEstimator to acquire the position and transmission vector (basically the direction) towards which I am looking at.
I want to couple the HeadPoseEstimator with ofxRay in order to create a plane of view and check if the direction where I turn my head to intersects with the plane. Which basically means, to check whether I look in my monitor (intersections should return true) and when I don’t.

At the moment I can not get any meaningful results as far as the interection is concerned and since I am uncertain about my math decomposition, I will describe that before providing some code. I also would like to understand the math. (yes I have seen the to wolfram website, but i can not understand how to apply the theory.)

ok, so the headPoseEstimator provides starting position and direction of the head. vectors are returning with 0,0 in the middle of my kinect 640x480 window.
I keeping my head fairly still, only turning my neck to look at the 4 corners of my monitor sequentially. at each edge I press a key and get the current pos + dir vectors from headPoseEstimator.

now I create an ofxRay::Plane using the 4 direction vectors registered in the previous step. note thatdir.z = 0 (so the plane will be drawn exactly in front my kinect, and the plane’s normal vector should point directly into (or out of) the kinect camera (right?).

I initialize a plane as

plane = ofPlane( ofVec3f( 0,0,0 ) , ofVec3f( 0,0,1 ));

so the plane’s normal vector should be looking away from the kinect (right?)

So once I have the dir vectors for all 4 edges of my monitor (saved in viewCorners), I can create my plane, which I do in the following way. This is only run once.

``````        ofVec3f cen = getCenterOfMass(ofVec3f(viewCorners),  \
ofVec3f(viewCorners), ofVec3f(viewCorners), ofVec3f(viewCorners));
plane.setCenter( cen );
plane.setInfinite( false );
``````

with the plane in place (is it?) I can now update the ray again with every new dir vector I get from the estimator.
in setup, I set the origin of my ray at

``````ofVec3f rayPos = ofVec3f( 0, 0, 0);
ofVec3f rayTransVec = ofVec3f( 0 , 0 , -1); //this is just a dummy intial transVector
ray = ofRay( rayPos , rayTransVec );
``````

during update(), I use the dir vector from head pose estimation to update the transmission vector of my ray and use that to verify the intersection of the plane with the ray, as :

``````        ray.setTranmissionVector( faceDirection );
ofVec3f intersectionPoint;
bPlaneRayIntersection = plane.intersect( ray , intersectionPoint );
``````

now for typical plane corner values
 = (-114 , -90, 0)
 = (145 , -114, 0)
 = (95, 37, 0)
 = (-56, 22, 0)

The plane characteristics are:
center = -17.5 , -36 , 0
normal = 0, 0, 1
up = 0,0,0

the ray has origin (0,0,0) and transmission vector (28, -26,685). This seems to lie within the corners of the plane above yet plane.intersection always returns false. why? what am I missing?

why does the ray have a z value? my ray should be infinite, but this random high value doesn’t convince me. if it is related tothe value of “u” from “ray = s + u*t” taken from https://github.com/elliotwoods/ofxRay/tree/0.8.0 , then how do I control the “u” parameter

additionally, my plane should not be infinite. going back to the previous link it says that I should set the 2D vector “bounds” by there is no such variable in the ofPlane class. additionally, it is not clear to me how should we treat the “up” vector. In any case the ofxRay example shows a clearly non-infinite plane when run without end extra code involving the “bounds” or “up” vector.