def distancePointSegment(a,Vbc,b,c): #returns min_distance between bc and a and the point of intersection of perpendicular from a on bc
	
	Vab=Vector.from_points(b, a)
	Vac=Vector.from_points(c, a)
	zero_vector=Point(0,0,0)
	min_distance=100
	final_point=[]
	type=[]
	if Vbc.magnitude()<.000001:
		return [9999999,[a.x,a.y]]
	if abs(Vab.dot(Vbc)/Vbc.magnitude())<= Vbc.magnitude() and abs(Vac.dot(Vbc)/Vbc.magnitude())<= Vbc.magnitude():
		min_distance=(Vab.cross(Vbc)).magnitude()/Vbc.magnitude()
		
		perpendicular_point_vector=Vbc.multiply(abs(Vab.dot(Vbc))/Vbc.magnitude()/Vbc.magnitude())
		final_point=perpendicular_point_vector.sum(Vector.from_points(zero_vector,b))
		type="middle"
	else :
		min_distance=min([Vab.magnitude(),Vac.magnitude()])
		if min_distance==Vab.magnitude():
			final_point=Vector.from_points(zero_vector, b)
			type="vertex"
		else:
			final_point=Vector.from_points(zero_vector, c)
			type="vertex"

	return [min_distance,[final_point.x,final_point.y]]
Пример #2
0
 def getFaceNormal(self, face):
     points = []
     for v in face:
         points.append(Point(v[0], v[1], v[2]))
     vecA = Vector.from_points(points[0], points[1])
     vecB = Vector.from_points(points[0], points[2])
     vecResult = Vector.cross(vecA, vecB)
     return vecResult
def findShortestDistanceSegments(a1,a2,b1,b2): #returns the min_distance between two segments, perpendicular intersection point and the point from which the distance is calculated
	
	Va=Vector.from_points(a1, a2)
	Vb=Vector.from_points(b1, b2)
	
	if intersect(a1,a2,b1,b2):
		return[[0,[0,0]],a1]
	result=[]
	result.append([distancePointSegment(a1,Vb,b1,b2),a1])
	result.append([distancePointSegment(a2,Vb,b1,b2),a2])
	result.append([distancePointSegment(b1,Va,a1,a2),b1])
	result.append([distancePointSegment(b2,Va,a1,a2),b2])
	distances_list=[result[0][0],result[1][0],result[2][0],result[3][0]]
	final_result=result[distances_list.index(min(distances_list))]
	return final_result
Пример #4
0
 def unit_vector(self):
     directional_vector = self.attached_body.rotate_vector_by_orientation(
         rotate_vector(vector=DIRECTIONAL_VECTORS[self.attached_panel.side],
                       roll=0,
                       pitch=(DEGREES_TO_RADIANS * 90) - self.get_pitch(),
                       yaw=(DEGREES_TO_RADIANS * 90) - self.get_yaw()))
     return Vector.from_points(self.position, directional_vector).unit()
Пример #5
0
def get_normal(tri):
    """in: 3 verts, out normal (nx, ny,nz) with length 1
    """
    (v0, v1, v2) = tri
    p0 = Point.from_list(v0.get())
    p1 = Point.from_list(v1.get())
    p2 = Point.from_list(v2.get())
    a = Vector.from_points(p1, p0)
    b = Vector.from_points(p1, p2)
    #print p0,p1, p2
    #print a,b
    c = a.cross(b)
    #print c
    m = float(c.magnitude())

    normal = [c.x / m, c.y / m, c.z / m]
    return normal
Пример #6
0
 def get_sensor_radius_at_point(self, point):
     slope = tan(self.focus * DEGREES_TO_RADIANS)
     return slope * Vector.from_points(self.position, point).magnitude()
Пример #7
0
def dist(v1, v2):
    ''' distance between 2 vertices'''
    p1 = Point.from_list(v1.get())
    p2 = Point.from_list(v2.get())
    v = Vector.from_points(p1, p2)
    return v.magnitude()