-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLine.py
More file actions
31 lines (21 loc) · 1.51 KB
/
Copy pathLine.py
File metadata and controls
31 lines (21 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from Vector3D import *
class Line:
"""Vectorial data structure representing a line"""
def __init__(self,point,direction):
self.position= point
self.direction = direction.normalize()
def __repr__(self):
return "Line({},{})".format(self.position,self.direction.normalize())
def origin_point(self):
return self.position - self.position.x*self.direction
def point(self,t):
return self.position + t*self.direction
def plane_intersect(self,plane):
"""Calculates the intersection of a plane of the plane class and itself, requires the use of the plane module! if it does not find an intercept it retuns None"""
#print("{},{}".format((plane.distance_to_origin() - plane.normal.x*self.position.x - plane.normal.y*self.position.y - plane.normal.z*self.position.z),(plane.normal.x*self.direction.x + plane.normal.y*self.direction.y + plane.normal.z*self.direction.z)))
dp = self.direction.dot_product(plane.normal)
if dp == 0:
raise Exception("Line {} and plane {} are parallel".format(self, plane))
return None
tVal=((plane.position-self.position).dot_product(plane.normal))/ dp # ACCORDING to the formula on wikipedia vector form: https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection
return Vector(tVal*self.direction.x + self.position.x,tVal*self.direction.y + self.position.y,tVal*self.direction.z + + self.position.z)