Skip to content

Instantly share code, notes, and snippets.

@NSDesign
Last active October 7, 2015 01:42
Show Gist options
  • Select an option

  • Save NSDesign/6c28969d150f47f9ace2 to your computer and use it in GitHub Desktop.

Select an option

Save NSDesign/6c28969d150f47f9ace2 to your computer and use it in GitHub Desktop.
import math
node = hou.pwd()
geo = node.geometry()
# Lines Construction
hasInputs = True if len(node.inputs()) > 0 else False
if hasInputs == False:
line1_Pos = [(0,0,0), (1,1,0)]
line1 = geo.createPolygon()
line1.setIsClosed(False)
line2_Pos = [(0,1,0), (1,0,0)]
line2 = geo.createPolygon()
line2.setIsClosed(False)
for p in line1_Pos:
pt = geo.createPoint()
pt.setPosition(p)
line1.addVertex(pt)
for p in line2_Pos:
pt = geo.createPoint()
pt.setPosition(p)
line2.addVertex(pt)
# Intersection Implementation
pts = geo.iterPoints()
p0 = pts[0]
p1 = pts[1]
p2 = pts[2]
p3 = pts[3]
a = p1.position() - p0.position()
b = p3.position() - p2.position()
C = p0.position()
D = p2.position()
e = a
f = b
g = D - C
H = f.cross(g)
K = f.cross(e)
h = H.length()
k = K.length()
a = K.normalized()
b = H.normalized()
d = a.dot(b)
if hou.almostEqual(d, 1.0) or hou.almostEqual(d, -1.0):
l = (h / k) * e * math.copysign(1, d)
i = C + l
p = geo.createPoint()
p.setPosition(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment