Exemple #1
0
    def update_all(self):
        cx, cy = self.cxy
        wx, wy = self.wxy
        dx, dy = wx - cx, wy - cy
        r, angle = cart2pol(dx, dy)

        ex, ey = pol2cart(r + self.stickout, angle)

        self.artists["main_arrow"].set_positions(self.cxy, (cx + ex, cy + ey))
        self.artists["line"].set_data([cx, wx], [cy, wy])

        arc = self.artists["arc"]
        arc.angle = angle
        arc.width = 2 * r
        arc.height = 2 * r
        arc.set_center(self.cxy)

        r_ext = r + self.stickout
        hspan = self.span / 2
        p1_angle = angle - hspan
        p1 = {"tail": pol2cart(r, p1_angle), "head": pol2cart(r_ext, p1_angle)}
        self.artists["prong1"].set_data(
            [cx + p1["tail"][0], cx + p1["head"][0]],
            [cy + p1["tail"][1], cy + p1["head"][1]],
        )

        p2_angle = angle + hspan
        p2 = {"tail": pol2cart(r, p2_angle), "head": pol2cart(r_ext, p2_angle)}
        self.artists["prong2"].set_data(
            [cx + p2["tail"][0], cx + p2["head"][0]],
            [cy + p2["tail"][1], cy + p2["head"][1]],
        )
Exemple #2
0
    def coords_to_angle(interactors: List[Dict[str, Any]]):
        for interactor in interactors:
            cx, cy = interactor["cxy"]
            wx, wy = interactor.pop("wxy")

            _, angle = cart2pol(wx - cx, wy - cy)
            interactor["angle"] = round(angle, 1)
        return interactors
Exemple #3
0
    def angle(self) -> float:
        dx = self.wxy[0] - self.cxy[0]
        dy = self.wxy[1] - self.cxy[1]

        _, angle = cart2pol(dx, dy)
        return angle
Exemple #4
0
 def angle(self) -> float:
     cx, cy = self.cxy
     wx, wy = self.wxy
     dx, dy = wx - cx, wy - cy
     _, angle = cart2pol(dx, dy)
     return angle
Exemple #5
0
    def init_artists(self):
        main_arrow_props: Dict[str, Any] = {
            "alpha": 0.5 if self.active else 0.2,
            "animated": True,
            "arrowstyle": "->,head_length=10,head_width=7",
            "color": self.color,
            "linestyle": "solid",
        }

        line_props: Dict[str, Any] = {
            "alpha": 0.7 if self.active else 0.3,
            "animated": True,
            "color": self.color,
            "linestyle": "",
            "marker": "x",
            "markerfacecolor": self.color,
            "markersize": 8,
        }

        arc_props: Dict[str, Any] = {
            "alpha": 0.5 if self.active else 0.3,
            "animated": True,
            "color": self.color,
            "linestyle": "dashed",
        }

        prong_props: Dict[str, Any] = {
            "alpha": 0.5 if self.active else 0.2,
            "animated": True,
            "color": self.color,
            "linestyle": "dashed",
            "linewidth": 1,
        }

        cx, cy = self.cxy
        wx, wy = self.wxy
        dx, dy = wx - cx, wy - cy
        r, angle = cart2pol(dx, dy)
        hspan = self.span / 2

        ex, ey = pol2cart(r + self.stickout, angle)

        # main arrow
        main_arrow = FancyArrowPatch(
            posA=self.cxy, posB=(ex + cx, ey + cy), **main_arrow_props
        )
        self.artists["main_arrow"] = main_arrow
        self.axes.add_patch(main_arrow)

        # line
        (line,) = self.axes.plot([cx, wx], [cy, wy], **line_props)
        self.artists["line"] = line
        self.axes.add_line(line)

        # arc
        arc = Arc(
            xy=self.cxy,
            width=2 * r,
            height=2 * r,
            angle=angle,
            theta1=-hspan,
            theta2=hspan,
            **arc_props
        )
        self.artists["arc"] = arc
        self.axes.add_patch(arc)

        # prongs
        r_ext = r + self.stickout
        p1_angle = angle - hspan
        p1 = {"tail": pol2cart(r, p1_angle), "head": pol2cart(r_ext, p1_angle)}
        (prong1,) = self.axes.plot(
            [cx + p1["tail"][0], cx + p1["head"][0]],
            [cy + p1["tail"][1], cy + p1["head"][1]],
            **prong_props
        )
        self.artists["prong1"] = prong1
        self.axes.add_line(prong1)

        p2_angle = angle + hspan
        p2 = {"tail": pol2cart(r, p2_angle), "head": pol2cart(r_ext, p2_angle)}
        (prong2,) = self.axes.plot(
            [cx + p2["tail"][0], cx + p2["head"][0]],
            [cy + p2["tail"][1], cy + p2["head"][1]],
            **prong_props
        )
        self.artists["prong2"] = prong2
        self.axes.add_line(prong2)