Beispiel #1
0
    def __new__(cls, *args, normal=None, centroid=None, **kwargs):

        out = super().__new__(cls, *args, **kwargs)
        if centroid is None:
            try:
                centroid = out.centroid
                centered = out - centroid
            except:
                temp = np.zeros((centroid.shape[0], out.shape[-1] ))
                temp[:out.shape[0]] = out
                out = temp
                out = super().__new__(cls, out, **kwargs)
                centroid = out.centroid
                centered = out - centroid
        else:
            try:
                centered = out - centroid
            except:
                temp = np.zeros((centroid.shape[0], out.shape[-1] ))
                temp[:out.shape[0]] = out
                out = temp
                out = super().__new__(cls, out, **kwargs)
                centered = out - centroid

        if normal is None:
            normal = math.approximate_normal(centered)
        normal = arrays.ColumnVector(normal)
        to_plane = centered - normal @ (centered.T @ normal).T
        return math.close_curve(to_plane+centroid).view(cls)
Beispiel #2
0
    def circle(cls, r, npts=100, centroid='origin'):
        if centroid == 'origin':
            centroid = np.zeros((2, 1))

        theta = np.linspace(-np.pi, np.pi, npts)

        x = r*np.cos(theta)
        y = r*np.sin(theta)

        return cls(np.stack([x, y], axis=0)).make_3d() + arrays.ColumnVector(centroid).make_3d()
Beispiel #3
0
 def get_landmark_vector(
     self,
     color=[0.3, 0.3, 0.5],
     check=['le', 'le', 'ge'],
 ):
     binary = self.threshholdRGBToBinary(color, check)
     landmark = binary.measure(0.8)[0]
     if len(landmark) > 0:
         vector = arrays.ColumnVector(np.mean(landmark, 0).T).make_3d()
         return vector
     else:
         return None
Beispiel #4
0
    def oriented_transport_frames(self, origin, jVector, return_index=True):

        origin_id = np.argmin(math.l2_norm(
            self - arrays.ColumnVector(origin)
        ))

        transportFrames = self.transport_frames()
        ijk_self = arrays.Basis(transportFrames[origin_id])
        jVector = arrays.ColumnVector(jVector).hat
        projected = jVector.project_to_plane(ijk_self[:, -1])
        j_new = math.normalize(
            projected.change_reference_frame(ijk_self)).squeeze()
        z_new = np.array([0, 0, 1])
        ijk_new = arrays.Basis(
            math.normalize(math.cross(j_new, z_new)), j_new, z_new
        )
        newTransportFrames = np.zeros_like(transportFrames)
        for i, frame in enumerate(transportFrames):
            newTransportFrames[i] = arrays.Basis(frame @ ijk_new)
        if return_index:
            return newTransportFrames, origin_id
        else:
            return newTransportFrames
Beispiel #5
0
 def initialize_column_vector(self, s):
     return arrays.ColumnVector([f(s) for f in self.dim_funcs])
Beispiel #6
0
 def calc_normal(self):
     centered = self - self.centroid
     return arrays.ColumnVector(
         math.approximate_normal(centered)
     )
Beispiel #7
0
 def calc_centroid(self):
     return arrays.ColumnVector(math.contour_centroid(self))
Beispiel #8
0
        x = y = z = np.linspace(0, 10, 10)
        curve = Curve(x, y, z)
        interp_curve = curve(
            np.linspace(0, 1, 100)
        )

        ax.scatter(*interp_curve)
        plt.show()

    if False:
        theta = np.linspace(-np.pi, np.pi, 10000)
        r = 1
        x = r * np.cos(theta)
        y = r * np.sin(theta)

        contour = Contour(x, y).make_3d() + arrays.ColumnVector(1, 2, 3)

        normal = contour.normal

        area = contour.area
        true_area = np.pi*r**2

        contour_centroid = contour.centroid()

        contour_interp = contour(
            np.linspace(0, 1, 100)
        )

        ax.scatter(*contour)
        ax.scatter(*contour_interp, color='red')
        ax.scatter(*contour_centroid, color='orange')