<Line|User's Guide|Ray>

Plane

See Javadoc

Definition

A plane is defined by the equation N . (X - X0) = 0 where N = (a, b, c) and passes through the point X0 = (x0, y0, z0). X defines another point on this plane (x, y, z).

N . (X - X0) = 0 can be described as (N . X) + (N . -X0) = 0

or

(ax + by + cz) + (-ax0-by0-cz0) = 0

where (-ax0-by0-cz0) = d

Where d is the negative value of a point in the plane times the unit vector describing the orientation of the plane.

This gives us the general equation: (ax + by + cz + d = 0)

Usage in jME

jME defines the Plane as ax + by + cz = -d. Therefore, during creation of the plane, the normal of the plane (a,b,c) and the constant d is supplied.

The most common usage of Plane is Camera frustum planes. Therefore, the primary purpose of Plane is to determine if a point is on the positive side, negative side, or intersecting a plane.

Plane defines the constants:

  • NEGATIVE_SIDE - represents a point on the opposite side to which the normal points.
  • NO_SIDE - represents a point that lays on the plane itself.
  • POSITIVE_SIDE - represents a point on the side to which the normal points.

These values are returned on a call to whichSide.

Example 1 - Determining if a Point is On the Positive Side of a Plane

Vector3f normal = new Vector3f(0,1,0);
float constant = new Vector3f(1,1,1).dot(normal);
Plane testPlane = new Plane(normal, constant);
 
int side = testPlane.whichSide(new Vector3f(2,1,0);
 
if(side == Plane.NO_SIDE) {
   System.out.println("This point lies on the plane");
}

Example 2 - For the Layperson

Using the standard constructor Plane(Vector3f normal, float constant), here is what you need to do to create a plane, and then use it to check which side of the plane a point is on.

package test;

import java.util.logging.Logger;

import com.jme.math.*;

/**
 *@author Nick Wiggill
 */

public class TestPlanes
{
	public static final Logger logger = Logger.getLogger(LevelGraphBuilder.class.getName());
	
	public static void main(String[] args) throws Exception
	{
		//***Outline.
		//This example shows how to construct a plane representation using
		//com.jme.math.Plane.
		//We will create a very simple, easily-imagined 3D plane. It will
		//be perpendicular to the x axis (it's facing). It's "centre" (if
		//such a thing exists in an infinite plane) will be positioned 1
		//unit along the positive x axis.
		
		//***Step 1.
		//The vector that represents the normal to the plane, in 3D space.
		//Imagine a vector coming out of the origin in this direction.
		//There is no displacement yet (see Step 2, below).
		Vector3f normal = new Vector3f(5f,0,0);
		
		//***Step 2.
		//This is our displacement vector. The plane remains facing in the
		//direction we've specified using the normal above, but now we are
		//are actually giving it a position other than the origin.
		//We will use this displacement to define the variable "constant"
		//needed to construct the plane. (see step 3)
		Vector3f displacement = Vector3f.UNIT_X;
		//or
		//Vector3f displacement = new Vector3f(1f, 0, 0);
		
		//***Step 3.
		//Here we generate the constant needed to define any plane. This
		//is semi-arcane, don't let it worry you. All you need to
		//do is use this same formula every time.
		float constant = displacement.dot(normal);
		
		//***Step 4.
		//Finally, construct the plane using the data you have assembled.
		Plane plane = new Plane(normal, constant);
				
		//***Some tests.
		logger.info("Plane info: "+plane.toString()); //trace our plane's information
		
		Vector3f p1  = new Vector3f(1.1f,0,0); //beyond the plane (further from origin than plane)
		Vector3f p2  = new Vector3f(0.9f,0,0); //before the plane (closer to origin than plane)
		Vector3f p3  = new Vector3f(1f,0,0); //on the plane
		
		logger.info("p1 position relative to plane is "+plane.whichSide(p1)); //outputs NEGATIVE
		logger.info("p2 position relative to plane is "+plane.whichSide(p2)); //outputs POSITIVE
		logger.info("p3 position relative to plane is "+plane.whichSide(p3)); //outputs NONE
	}
}

<Line|User's Guide|Ray>


/var/www/wiki/data/pages/plane.txt · Last modified: 2010/03/30 22:14 by nickza  
Recent changes · Show pagesource · Login

Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

subscribe to jME latest jme headlines


site design by bleedcrimson designs © 2008