Hi monkeys.

I am trying to determine whether a point is inside a square pyramid. I have a square planet and I want to know which face of the planet the player is on. So what I do is for each face in the planet, I get the corners of that face. I then construct 4 triangles using the corner points and the center of the planet. Basically what I do is construct a pyramid in the planet using the center and the 4 corners.

Like this:

For each face of the pyramid I get the cross product of the two corners and then normalize it, and get the dot product of the normalized vector and the playerâ€™s physics location. Iâ€™m getting weird results, and it doesnâ€™t seem to be working. Can someone look at my code? I donâ€™t have a source of where I got all the equations, it was a result of reading a bunch of forums and lots of googling:

[java]

public int getCurrentFaceOfPlanet(Planet planet)

{

for(int i = 0; i<=5; i++)

{

System.out.println("------------\nFace: â€ś+i+â€ť\n");

PlanetCorner[] corners = planet.getCornersForFace(i);

System.out.println("\nCorner Locations:\n");

System.out.println(corners[0].getWorldTranslation());

System.out.println(corners[1].getWorldTranslation());

System.out.println(corners[2].getWorldTranslation());

System.out.println(corners[3].getWorldTranslation());

```
Vector3f P1 = planet.getPlanetNode().getWorldTranslation();
Vector3f P2 = corners[0].getWorldTranslation();
Vector3f P3 = corners[1].getWorldTranslation();
Vector3f P4 = corners[2].getWorldTranslation();
Vector3f P5 = corners[3].getWorldTranslation();
Vector3f playerP = this.getPhysicsLocation();
Vector3f s1a = P2.subtract(P1);
Vector3f s1b = P3.subtract(P1);
Vector3f s1c = s1a.cross(s1b);
Vector3f s1n = s1c.normalize();
float s1d = playerP.dot(s1n);
Vector3f s2a = P3.subtract(P1);
Vector3f s2b = P4.subtract(P1);
Vector3f s2c = s2a.cross(s2b);
Vector3f s2n = s2c.normalize();
float s2d = playerP.dot(s2n);
Vector3f s3a = P4.subtract(P1);
Vector3f s3b = P5.subtract(P1);
Vector3f s3c = s3a.cross(s3b);
Vector3f s3n = s3c.normalize();
float s3d = playerP.dot(s3n);
Vector3f s4a = P5.subtract(P1);
Vector3f s4b = P2.subtract(P1);
Vector3f s4c = s4a.cross(s4b);
Vector3f s4n = s4c.normalize();
float s4d = playerP.dot(s4n);
System.out.println("1: "+s1d+" 2: "+s2d+" 3: "+s3d+" 4: "+s4d+"\nPlayer Loc: "+playerP);
}
return 0;
}
```

[/java]

getCornersForFace() returns the corners of that face number in a clockwise order. PlanetNode is at the center of the planet. What am I doing wrong? Sometimes the results for one face are all positive when I try this in 3 different faces, and sometimes negative, etc. The results never seem right. (The return statement is just a temporary placement until I get this working.) If Iâ€™m not clear enough let me know. Thanks!