Lately I've been having to perform a lot of vector math...what fun. Luckily the GPSE comes preloaded with helper functions and overloaded arithmetic operators. Here's today's nugget...projecting points to a plane.

Q: How can I use Python to project points to a plane?

A: To project any point to a given plane, all that is needed is a plane to project to and a point to project.

Below is a short script that uses GPSE math objects to calculate a projected point from a given plane and point. The script then creates feature to be added to the Model Manager or Graphics Scene. The .project() call on the Plane object is the helper math function used to create the Vector3D position needed to build the PointFeature that is added to the scene, it is the heart of the solution:

myProjectedPointPos = myPlane.project( myPointPos )

Here is the script:

import geoappall
for m in geoappall.execStrings: exec m in locals(), globals()

# calculate the position

# the plane to project to using the Plane ( Direction, Origin ) construction method
pDir = Vector3D( 0.2344, 0.665, 0.11 )
pOrg = Vector3D( 0.0344, 1.456, 10.125 )
myPlane = Plane( pDir, pOrg )

# the position to project
myPointPos = Vector3D( 5.125, -2.45, 0.0125 )

# the projected position
myProjectedPointPos = myPlane.project( myPointPos )

# create the features
myPointFeature = PointFeature() = u"myPoint"
myPointFeature.position = myPointPos

myProjectedPointFeature = PointFeature() = u"myProjectedPoint"
myProjectedPointFeature.position = myProjectedPointPos

myPlaneFeature = PlaneFeature() = u"myPlane"
myPlaneFeature.origin = pOrg
myPlaneFeature.normal = pDir
myPlaneFeature.uRange = Vector2D( -12, 12 )
myPlaneFeature.vRange = Vector2D( -12, 12 )

# add them to the World Object in the model manager (scene)
models = geoapp.getModels()
for model in models:
# Find the world object and make it active.
if == "World":
geoapp.addFeature( model, myPointFeature )
geoapp.addFeature( model, myProjectedPointFeature )
geoapp.addFeature( model, myPlaneFeature )