Skip to content

Instantly share code, notes, and snippets.

@stevester94
Created November 10, 2015 00:25
Show Gist options
  • Select an option

  • Save stevester94/3155456d51972faac8f3 to your computer and use it in GitHub Desktop.

Select an option

Save stevester94/3155456d51972faac8f3 to your computer and use it in GitHub Desktop.
Calc normal given 3 points, python 3
import math
def calcPlaneNormal(x1, y1, z1, x2, y2, z2, x3, y3, z3):
nx1 = x1 - x2
ny1 = y1 - y2
nz1 = z1 - z2
mag1 = math.sqrt(nx1*nx1 + ny1*ny1 + nz1*nz1)
nx2 = x1 - x3
ny2 = y1 - y3
nz2 = z1 - z3
mag2 = math.sqrt(nx2*nx2 + ny2*ny2 + nz2*nz2)
nx1 = nx1 / mag1
ny1 = ny1 / mag1
nz1 = nz1 / mag1
nx2 = nx2 / mag2
ny2 = ny2 / mag2
nz2 = nz2 / mag2
cI = ny1*nz2 - nz1*ny2
cJ = nz1*nx2 - nx1*nz2
cK = nx1*ny2 - ny1*nx2
print(cI)
print(cJ)
print(cK)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment