Question

I'm trying to use a formulae from http://www.blackpawn.com/texts/pointinpoly/default.html the upper of the two options. (I have already used the lower).

I just can not seem to wrap my head around the CrossProduct(b-a, p1-a) etc. Could someone Please expand these for me. They are below.

function SameSide(p1,p2, a,b)
    cp1 = CrossProduct(b-a, p1-a)
    cp2 = CrossProduct(b-a, p2-a)
    if DotProduct(cp1, cp2) >= 0 then return true
    else return false

as I understand it they should come out to this.

##  Using the following as p=x,z, a=x,z, b=x,z, c=x,z
##  p=4,1 a=2,0 b=4,3 c=0,4
function SameSide(px, pz, ax, az, bx, bz, cx, cz){
    cp1x=(cx-bx*px-bx)
    cp1z=(cz-bz*pz-bz)
    cp2x=(cx-bx*ax-bx)
    cp2z=(cz-bz*az-bz)
    DotProd=(cp1x*cp2x+cp1z*cp2z)
}

But when trying this in Excel I get wrong answers again.

Please help! 8-|

Was it helpful?

Solution

Your DotProduct computation is correct. However, the cross product of 2 vectors v and w is :

cpx = vy*wz - vz*wy
cpy = vz*wx - vx*wz
cpz = vx*wy - vy*wx

where in your case, vx = bx-ax vy = by-ay and vz=bz-az, and wx=p1x-ax (or respectively p2x-ax) and similarly for y and z.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top