def createFromThreePoints(points): """Create an angle from 3 points.""" p1, p2, p3 = points v1 = Vector.createFromTwoPoints(p2, p1) v2 = Vector.createFromTwoPoints(p2, p3) angle = v2.angle() - v1.angle() return Angle(angle)
def show(self, context): """Show all the objects on screen.""" for object in self.objects: object.center.showMotion(context) object.show(context) l = len(self.objects) for i in range(l): for j in range(i + 1, l): points = self.objects[i].abstract | self.objects[j].abstract if points != []: self.objects[i].velocity *= 0 print(points) l1 = Segment(*points[:2]) l1.color = mycolors.GREEN l1.show(context) p = l1.center p.show(context, mode="cross", color=mycolors.RED) c1 = self.objects[i].center.abstract v = Vector.createFromTwoPoints(c1, p) v.color = mycolors.GREEN v.show(context, c1) v.norm = 1 v.color = mycolors.BLUE v.show(context, p) v.showText(context, p, 'up') v.rotate(math.pi / 2) v.show(context, p) v.showText(context, p, 'uo')
def enlarge(self, n): center = self.center for point in self.points: v = n * Vector.createFromTwoPoints(center, point) point.set(v(point)) # self._born *= n self.updateBorn()
def show(self, surface, points): """Show the angle between the points.""" p1, p2 = points #Need to be able to print arc of circles using pygame v1 = Vector.createFromTwoPoints(p1, p2) v1 = ~v1 v2 = v1 % self p3 = v2(p2) s1 = Segment(p1, p2) s2 = Segment(p2, p3) s1.show(surface) s2.show(surface)
def shoot(self,context): """Return a missile.""" #logging.warning("This function is only a test and should not be included in the body class but in a child class instead.""") keys=context.press() point=Point(*context.point()) if keys[K_SPACE]: center=Point(*self.position) direction=Vector.createFromTwoPoints(center,point) direction.norm=2 origin=Point.origin() form=Segment(origin,direction(origin)) position=copy.deepcopy(self.position+direction(origin)) velocity=direction+copy.deepcopy(self.velocity) return Missile(form,position,velocity)
def setCenter(self, nc): """Set the center of the material form.""" ac = self.getCenter() v = Vector.createFromTwoPoints(nc, ac) for point in self.points: point += v
def setStep(self, step): """Set the velocity of the form so the next step is the given one.""" self.velocity = Vector.createFromTwoPoints(*step)
def getVector(self, t=1, **kwargs): """Return the vector made of the actual point and the future one.""" p1 = self.abstract p2 = self.getNext(t).abstract return Vector.createFromTwoPoints(p1, p2, **kwargs)
s2.show(surface) p1 = s1.center p1.show(surface, color=mycolors.RED) p.showText(surface, "p") p1.showText(surface, "p1") p2.showText(surface, "p2") p3.showText(surface, "p3") pl = l1.crossLine(l2) if pl: pl.show(surface, color=mycolors.RED, mode="cross", width=3) pl.showText(surface, "pl") print("in s1:", pl in s1) print("in s2:", pl in s2) v1 = Vector.createFromTwoPoints(s1.p1, pl) v1.color = mycolors.BLUE v2 = s1.getVector() v2.color = mycolors.YELLOW print(abs(v1.angle - v2.angle) < e) print(v1.norm <= v2.norm) print(v1.norm, v2.norm) v2.show(surface, s1.p1) v2.showText(surface, s1.p1, text="v2") v1.show(surface, s1.p1) v1.showText(surface, s1.p1, text="v1") v1 = Vector.createFromTwoPoints(s2.p1, pl) v1.color = mycolors.BLUE
def crossCircle(self,other): """Determine if two circles are crossing.""" vector=Vector.createFromTwoPoints(self.center,other.center) return vector.norm<self.radius+other.radius
surface.control() surface.clear() surface.show() x,y=surface.point() c1.setPosition(x,y) if c1.crossCircle(c2): fill=False c1_border_color=mycolors.random() c2_border_color=mycolors.random() else: fill=True c1_area_color=mycolors.random() c2_area_color=mycolors.random() vector=Vector.createFromTwoPoints(c1.center,c2.center) vector.show(surface,c1.center,color=mycolors.GREEN) c1.show(surface,border_color=c1_border_color,area_color=c1_area_color,fill=fill) c1.showText(surface,"C1") c1.showRadius(surface) c2.show(surface,border_color=c2_border_color,area_color=c2_area_color,fill=fill) c2.showText(surface,"C2") c1.showRadius(surface) for c in cs: c.show(surface) surface.flip()
def getVectors(self): """Return the vectors that connect the points with their connections. Unlike the segments the vectors show the orientation.""" return [Vector.createFromTwoPoints(self.points[c[0]], self.points[c[1]],\ color=self.vector_color) for c in self.connections]