Example #1
0
    def _bezier_guide_channel(self, start, outer_width, inner_width, length, p2, p3):
        top_curve = CubicBezierCurve(
            (start, outer_width), (start + p2[0] * length / 2., outer_width - p2[1] * inner_width),
            (start + p3[0] * length / 2., inner_width + p3[1] * (outer_width - inner_width)),
            (start + length / 2., inner_width))
        bottom_curve = CubicBezierCurve((start + length / 2., inner_width),
                                        (start + length / 2. + p2[0] * length / 2., inner_width + p2[1] * inner_width),
                                        (start + length / 2. + p3[0] * length / 2.,
                                         outer_width - p3[1] * (outer_width - inner_width)),
                                        (start + length, outer_width))

        return Polygon(
            chain(zip(*top_curve.evaluate(np.linspace(0, 1, self._points_per_curve))), zip(*bottom_curve.evaluate(
                np.linspace(0, 1, self._points_per_curve))), ([(length, 0), (0, 0)])))
Example #2
0
    def add_cubic_bezier_path(self, p0, p1, p2, p3, width=None, **kwargs):
        """
        Add a cubic bezier path to the waveguide.

        Coordinates are in the "waveguide tip coordinate system", so the first point will probably be p0 == (0, 0).
        Note that your bezier curve undergoes the same restrictions as a parameterized path. Don't self-intersect it and
        don't use small bend radii.

        :param p0: 2 element tuple like coordinates
        :param p1: 2 element tuple like coordinates
        :param p2: 2 element tuple like coordinates
        :param p3: 2 element tuple like coordinates
        :param width: Width of the waveguide, as passed to :func:add_parameterized_path
        :param kwargs: Optional keyword arguments, passed to :func:add_parameterized_path
        :return: Changed waveguide
        :rtype: Waveguide
        """

        bezier_curve = CubicBezierCurve(p0, p1, p2, p3)

        self.add_parameterized_path(path=bezier_curve.evaluate,
                                    path_derivative=bezier_curve.evaluate_d1,
                                    width=width,
                                    path_function_supports_numpy=True,
                                    **kwargs)
        return self
Example #3
0
    def _bezier_guide_symm(self, start, width_1, width_2, length, p2, p3):
        top_curve = CubicBezierCurve(
            *[(start, width_1 / 2), (start + p2[0] * length, width_1 / 2 - p2[1] * width_2 / 2),
              (start + p3[0] * length, width_1 / 2 - p3[1] * (width_1 / 2 - width_2 / 2)),
              (start + length, width_2 / 2)])

        bottom_curve = CubicBezierCurve(
            *[(start, -width_1 / 2), (start + p2[0] * length, -width_1 / 2 + p2[1] * width_2 / 2),
              (start + p3[0] * length, -width_1 / 2 + p3[1] * (width_1 / 2 - width_2 / 2)),
              (start + length, -width_2 / 2)])

        y_bottom = bottom_curve.evaluate(np.linspace(1, 0, self._points_per_curve))
        y_top = top_curve.evaluate(np.linspace(0, 1, self._points_per_curve))

        return Polygon(chain(zip(y_top[0], y_top[1]), zip(y_bottom[0], y_bottom[1])))