View Full Version : Determining if point lies on either side of a plane . . .

05 May 2009, 05:42 PM
Ok guys, so heres what I need:

I need to determine if any vertecies are on a certain side of a plane. Im doing a lot of poly cut operations, and some of them are meaningless, because its cutting away geometry that doesn't exist. SO im thinking I can determine if there would be anything to cut by seeing if any verts exist on the opposite side of the cut plane.

So far I have a working example:
int $isClipping = 0;
int $numVerts[] = `polyEvaluate -v pSphere1`;
// Get worldspace translate of vert
float $vertPos[] = `xform -q -ws -t ("pSphere1.vtx[" + $i + "]")`;
vector $vertVec = <<$vertPos[0],$vertPos[1],$vertPos[2]>>;

// Get plane normal
//string $pNormal[] = `polyInfo -fn pPlane1`;
//string $buff[] = {};
//tokenize $pNormal[0] $buff;
//print $buff;
//vector $pNorm = <;
vector $pNorm = <<0,1,0>>;

// Multiply normal times pos
vector $result = $vertVec * $pNorm;

// Get average value
float $average = ((($result.x) + ($result.y) + ($result.z)) / 3);

// Test
if($average < 0)
if($isClipping == 0)
$isClipping = 1;
if($isClipping == 0)

Which is fine, if you put that in an expression and animate a sphere moving up and down above the ground plane, it will tell you once the sphere intersects and moves below the ground plane.

I am assuming that if I multiply the normal by the transformation matrix of a plane, it will give me an accurate worldspace position of the normal, as opposed to just using a ground plane (0,1,0) ?

So my questions are these:
1) How would I go about finding the worldspace position of a plane's normal? How do I multiply the matrix by the normal? (ive never used matricies)

2) The script is decent, but its not as fast as I would like it to be. Would doing this thru the API be significantly faster? I would like to use the api through Python, since my main script is in Python, so if anyone could be so kind as to help me convert this into Python API compliant, I would be super greatful. ( Only if this would speed it up, of course )

Well, that's what I got. Any ideas??

05 May 2009, 04:36 PM
you want the dot product method of this thread....

it is the very first post with code in it....the one by _stev_

CGTalk Moderation
05 May 2009, 04:36 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.