# How to know 3D ofPoints inside a ofCube

Hello;

I´m trying to catch some 3d Particle captured from the ofKinect in order to trace them.
I´m stocked thinking how to:

• Make a 3D cube from the 4 ofPoints of the back of the cube.
• render just the ofPoint that are inside it

for now I just get this: by:

``````
---------- update

if (ptsCnt > 3){
ptsCnt = 0;

ofVec3f linA = surface - surface;
ofVec3f loc = surface + (linA/2);
cam.setTarget(loc);

ofVec3f distance = linA;
ofVec3f linB = surface - surface;
linB.normalize();
distance.perpendicular(linB);
cam.setGlobalPosition(loc * distance);
cam.setDistance(100);

}

------ draw

// 3D POINTS
ofSetColor(255);
ofPoint p;

glBegin(GL_POINTS);
int step = panel.getValueF("definition");
for(int y = 0; y < h; y += step) {
for(int x = 0; x < w; x += step) {
p = kinect.getWorldCoordinateFor(x, y) * 400;
glVertex3f(p.x, p.y, p.z);
}
}
glEnd();

// 3D Surface
ofFill();
ofSetColor(250, 0, 0,100);
glBegin(GL_POLYGON);
for(int i=0;i<4;i++)
glVertex3f(surface[i].x,surface[i].y,surface[i].z);
glEnd();

ofSetColor(0, 0, 255,255);
ofLine(surface, surface);
ofLine(surface, surface);

``````

the Point order is this:

``````

 --- 
|       |
 --- 

``````

I usualy do something like:

``````

if ( ( x > space->xLeft) )
& ( x < space->xRight)
& ( y > space->yTop)
& ( y < space->yBottom)
& ( z > space->zFront)
& ( z < space->zBack) )

``````

But in this case seams imposible because I´ll have 8 points of the corners instad 8 positions of the walls.

I don´t have a mathematical knowledge background so this seems like something posible but really really complicated to me.

thanks

Patricio

Every face of the cube defines a plane, so what you need to do is make sure that a point is on the wanted side of the plane for every face of the cube.

One way to do this is, to find the normal to each face of the cube using the cross product and then use the dot product to make sure the point it is on the wanted side of the plane.