Beispiel #1
0
 def from_point_and_two_vectors(cls, point, v1, v2):
     v1 = Vector(*v1)
     v2 = Vector(*v2)
     n = Vector.cross(v1, v2)
     n.unitize()
     plane = cls()
     plane.point = Point(*point)
     plane.normal = n
     return plane
Beispiel #2
0
 def basis(self):
     a, b, c = self.normal
     u = 1.0, 0.0, -a / c
     v = 0.0, 1.0, -b / c
     return [
         Vector(*vector, unitize=True)
         for vector in orthonormalise_vectors([u, v])
     ]
Beispiel #3
0
 def frame(self):
     """The local coordinate frame."""
     o = self.center
     w = self.normal
     p = self.points[0]
     u = Vector(p, o)
     u.normalize()
     v = w.cross(u)
     return o, u, v, w
Beispiel #4
0
    def __sub__(self, other):
        """Create a vector from other to self.

        Parameters:
            other (sequence, Point): The point to subtract.

        Returns:
            Vector: A vector from other to self
        """
        x = self.x - other[0]
        y = self.y - other[1]
        z = self.z - other[2]
        return Vector(x, y, z)
Beispiel #5
0
 def normal(self):
     """The (average) normal of the polygon."""
     o = self.center
     points = self.points
     a2 = 0
     normals = []
     for i in range(-1, len(points) - 1):
         p1  = points[i]
         p2  = points[i + 1]
         u   = [p1[_] - o[_] for _ in range(3)]
         v   = [p2[_] - o[_] for _ in range(3)]
         w   = cross_vectors(u, v)
         a2 += sum(w[_] ** 2 for _ in range(3)) ** 0.5
         normals.append(w)
     n = [sum(axis) / a2 for axis in zip(*normals)]
     n = Vector(n)
     return n
Beispiel #6
0
        plane = (plane.point, plane.normal)
        return project_point_plane(self, plane)


# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == '__main__':

    # import timeit
    # t0 = timeit.timeit('points = [Point(i, i, i) for i in xrange(100000)]', 'from __main__ import Point', number=100)
    # t1 = timeit.timeit('points = [[i, i, i] for i in xrange(100000)]', 'from __main__ import Point', number=100)
    # print(t0 / t1)

    from compas.geometry.objects import Plane

    from compas.geometry import projection_matrix

    point = Point(0.0, 0.0, 0.0)
    normal = Vector(0.0, 0.0, 1.0)
    plane = Plane.from_point_and_normal(point, normal)

    test = Point(1.0, 2.0, 3.0)

    P = projection_matrix()

    point.transform(P)

    print(point)
Beispiel #7
0
 def from_point_and_normal(cls, point, normal):
     plane = cls()
     plane.point = Point(*point)
     plane.normal = Vector(*normal)
     plane.normal.unitize()
     return plane
Beispiel #8
0
            for vector in orthonormalise_vectors([u, v])
        ]


# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == '__main__':

    from compas.visualization.viewers.viewer import Viewer
    from compas.visualization.viewers.core.drawing import xdraw_points
    from compas.visualization.viewers.core.drawing import xdraw_lines

    base = Point(1.0, 0.0, 0.0)
    normal = Vector(1.0, 1.0, 1.0)

    plane = Plane.from_point_and_normal(base, normal)

    basis = plane.basis()

    points = [{'pos': base, 'color': (1.0, 0.0, 0.0), 'size': 10.0}]

    lines = []

    for vector in basis + [plane.normal]:
        lines.append({
            'start': base,
            'end': base + vector,
            'color': (0.0, 0.0, 0.0),
            'width': 3.0