예제 #1
0
 def _planar_planar(self, other):
     crossSO = self.normal * other.normal
     # are we coplanar (Planar) or parallel (Nowhere)?
     if crossSO.zero():
         if self.accepts(other.point): return self
         return Nowhere()
     # find the intersection (Linear)
     dir = crossSO
     point = V()
     if not zero(crossSO[2]):
         point[0] = (other.normal[1] * self.d -
                     self.normal[1] * other.d) / crossSO[2]
         point[1] = (self.normal[0] * other.d -
                     other.normal[0] * self.d) / crossSO[2]
         point[2] = 0.0
     elif not zero(crossSO[1]):
         point[0] = (self.normal[2] * other.d -
                     other.normal[2] * self.d) / crossSO[1]
         point[1] = 0.0
         point[2] = (other.normal[0] * self.d -
                     self.normal[0] * other.d) / crossSO[1]
     elif not zero(crossSO[0]):  # else:
         point[0] = 0.0
         point[1] = (other.normal[1] * self.d -
                     self.normal[1] * other.d) / crossSO[0]
         point[2] = (self.normal[0] * other.d -
                     other.normal[0] * self.d) / crossSO[0]
     return Linear(point, point + dir)
예제 #2
0
 def _linear_linear(self, other):
     # linear vs linear
     # are we colinear (self) or parallel (Nowhere)?
     dirS = self.pointB - self.pointA
     dirO = other.pointB - other.pointA
     crossSO = dirO * dirS
     if crossSO.zero():
         if self.accepts(other.pointA): return self
         return Nowhere()
     # make an arbitrary line joining our two lines; get their crosses
     # if the crosses are parallel, the three form a coplanar triangle
     # if the crosses are not parallel, our lines don't meet (Nowhere)
     span = self.pointA - other.pointA
     crossO = span * dirO
     if crossO.zero(): return Unity(self.pointA)
     crossS = span * dirS
     if crossS.zero(): return Unity(other.pointA)
     crossXSO = crossO * crossS
     if not crossXSO.zero(): return Nowhere()
     # find the intersection (Unity)
     dist = 0.0
     if not zero(crossSO[2]):
         dist = crossO[2] / crossSO[2]
     elif not zero(crossAB[1]):
         dist = crossO[1] / crossSO[1]
     elif not zero(crossAB[0]):  # else:
         dist = crossO[0] / crossSO[0]
     return Unity(self.pointA + (dirS * dist))
예제 #3
0
def is_point_on_line(la, dir, p):
    if not zero(dir[0]):
        alpha = (p[0] - la[0]) / dir[0]
        y = dir[1] * alpha + la[1]
        z = dir[2] * alpha + la[2]
        return equal(y, p[1]) and equal(z, p[2])
    elif not zero(dir[1]):
        alpha = (p[1] - la[1]) / dir[1]
        z = dir[2] * alpha + la[2]
        return equal(la[0], p[0]) and equal(z, p[2])
    elif not zero(dir[2]):  # else:
        return equal(la[0], p[0]) and equal(la[1], p[1])
    return False
예제 #4
0
 def _circular_coplanar_circular(self, other):
     cc = other.point - self.point
     d = cc.magnitude()
     rS = self.radius
     rO = other.radius
     # too far apart?
     if (rS + rO) < d - EPSILON:
         return Nowhere()
     # equal or circumscribed?
     if zero(d):
         if equal(rS, rO):
             return self
         return Nowhere()
     # tangent?
     if equal(d, rS + rO):
         cc = cc.magnitude(rS)
         return Unity(self.point + cc)
     # find the midpoint where the "radical line" (chord) crosses cc
     term = d * d - rS * rS + rO * rO
     xS = term / 2 * d
     xO = d - xS
     # find the length of the radical line
     leg = 4 * d * d * rS * rS - term * term
     yy = 1 / d * sqrt(leg)
     y = yy / 2
     # find the intersection points
     cross = cc * self.normal
     chord = cc * cross
     chord = chord.magnitude(y)
     mark = cc
     mark = mark.magnitude(xS)
     mark += self.point
     return Duality(mark + chord, mark - chord)
예제 #5
0
 def __init__(self, point, normal, radius):
     Constraint.__init__(self)
     if zero(radius):
         raise ValueError, 'A circle must have a non-zero radius.'
     self.point = V(point)
     self.normal = V(normal).normalize()
     self.radius = abs(float(radius))
     self.d = self.normal.dot(self.point)
예제 #6
0
 def _planar_linear(self, other):
     dir = other.dir
     dot = self.normal.dot(dir)
     # are we coplanar (Linear) or parallel (Nowhere)?
     if zero(dot):
         if self.accepts(other.pointA): return other
         return Nowhere()
     # find the intersection (Unity)
     intersect = intersect_plane_and_line(self.point, self.normal,
                                          other.pointA, other.dir)
     return Unity(intersect)
예제 #7
0
    def _spherical_spherical(self, other):
        cc = other.point - self.point
        d = cc.magnitude()
        rS = self.radius
        rO = other.radius
        # too far apart?
        if (rS + rO) < d - EPSILON:
            return Nowhere()
        # equal or circumscribed?
        if zero(d):
            if equal(rS, rO):
                return self
            return Nowhere()
        # tangent?
        if equal(d, rS + rO):
            cc = cc.magnitude(rS)
            return Unity(self.point + cc)
        if max(rS, rO) - (d + min(rO, rS)) > 0:
            #One sphere included in another
            return Nowhere()
        # find the midpoint where the "radical line" (chord) crosses cc
        #print d,rS,rO
        #print rS - (d+rO)
        term = d * d - rS * rS + rO * rO
        #print term
        #term =  rS*rS - rO*rO
        xS = term / (2 * d)
        #print xS
        xO = d - xS
        # find the length of the radical line
        #leg = 4*d*d*rS*rS - term*term
        #yy = 1/d * sqrt(leg)
        #y = yy/2
        y = sqrt(rS * rS - xO * xO)
        # find the intersection points

        cc.normalize()
        #print cc,xS
        mark = cc
        mark = mark.magnitude(xO)
        mark += self.point
        return Circular(mark, cc, y)
예제 #8
0
 def __init__(self, point, radius):
     Constraint.__init__(self)
     if zero(radius):
         raise ValueError, 'A sphere must have a non-zero radius.'
     self.point = V(point)
     self.radius = abs(float(radius))
예제 #9
0
def is_point_on_plane(ppoint, normal, p):
    return zero(distance_from_plane(ppoint, normal, p))
예제 #10
0
	def begin_training_1 (self) :
		self.prototype_numerators = list ()
		self.prototype_denominators = list ()
		for index in xrange (self.prototype_count) :
			self.prototype_numerators.append (vectors.zero (self.vector_length))
			self.prototype_denominators.append (0)