Ejemplo n.º 1
0
 def intersect_point(self,s):
     """ Returns the intersection of this segment with the segment s """
     if self.collide_segment(s):
         lf = self.get_line()
         ls = s.get_line()
         ret = lf.intersect_point(ls) #Get the intersection point of lines extracted from segments
         if isinstance(ret,Line): #If segments have the same line
             #Cut a segment from this line
             if ret.vert: #Vertical line
                 x = self.p1.x
                 #get y coord
                 miny = max(self.get_min_y(),s.get_min_y())
                 maxy = min(self.get_max_y(),s.get_max_y())
                 #Compute segment
                 p1 = Vector(x,miny)
                 p2 = Vector(x,maxy)
             else: #Other line
                 #get x coord
                 minx = max(self.get_min_x(),s.get_min_x())
                 maxx = min(self.get_max_x(),s.get_max_x())
                 #Compute segment
                 p1 = Vector(minx,ret.a*minx+ret.b)
                 p2 = Vector(maxx,ret.a*maxx+ret.b)
             return Segment(p1,p2)
         return ret
     else:
         return None
Ejemplo n.º 2
0
    def __init__(self, left=0, top=0, width=0, height=0):
        if width < 0:
            raise WrongRectWidth()
        if height < 0:
            raise WrongRectHeight()

        self.position = Vector(left, top)
        self.dimension = Vector(width, height)
Ejemplo n.º 3
0
 def get_poly(self):
     """ Returns a polygon of the Rect (cf Polygon) """
     (l, t, w, h) = self.get_coord()
     v1 = Vector(l, t)
     v2 = Vector(l + w, t)
     v3 = Vector(l + w, t + h)
     v4 = Vector(l, t + h)
     box = Polygon([v1, v2, v3, v4])
     return box
Ejemplo n.º 4
0
 def __init__(self):
     self.__origin = Vector(
         0, 0
     )  # Origine du Transformable (0,0) and constant for now (it's easier this way)
     self.__position = Vector(
         0, 0)  # Coordonnees du Transformable dans l'environnement
     self.__rotation = 0  # Rotation actuelle du Transformable
     self.__scale = Vector(1., 1.)  # Ecard du transformable
     self.__transform = None  # Transformation
     self.__tr_need_up = True  # Transformation need update
     self.__inverse_transform = None  # Transformation inverse
     self.__inv_tr_need_up = True  # Inverse Transformation need update
Ejemplo n.º 5
0
 def intersect_point(self,l2):
     """ Returns the intersect point between two given lines """
     if self.vert:
         if l2.vert:
             if self.x == l2.x:
                 return Line(0,0,True,self.x)
             else:
                 return None
         else:
             return Vector(self.x,l2.a*self.x+l2.b)
     if l2.vert:
         return Vector(l2.x,self.a*l2.x+self.b)
     if self.a-l2.a == 0:
         if self.b == l2.b:
             return Line(self.a,self.b) #Superposed lines
         return None #Parallel lines
     x = (l2.b-self.b)/(self.a-l2.a)
     y = self.a*x+self.b
     return Vector(x,y)
Ejemplo n.º 6
0
 def set_scale(self, scale_x, scale_y):
     """ Set the scale """
     self.__scale = Vector(scale_x, scale_y)
     self.reset_update()
Ejemplo n.º 7
0
 def set_position(self, x, y):
     """ Set the positino of this """
     self.__position = Vector(x, y)
     self.reset_update()
Ejemplo n.º 8
0
 def transform_vect(self, v):
     """ Transforms a vector """
     arr = np.dot(self.matrix[:2, :], v.homogeneous())
     return Vector(arr[0][0], arr[1][0])
Ejemplo n.º 9
0
 def transform_point(self, x, y):
     """ Transforms a point x,y """
     return self.transform_vect(Vector(x, y))
Ejemplo n.º 10
0
 def get_mass_center(self):
     """ Returns the barycentre of this polygon """
     p = Vector(0,0)
     for o in self.get_points():
         p += o
     return p/len(self.get_points())