コード例 #1
0
    def __init__(self, points):
        assert len(points) >= 3
        assert reduce(operator.and_,
                      [isinstance(p, euclid.Point3) for p in points])
        self.plane = euclid.Plane(points[0], points[1], points[2])
        n = self.plane.n
        self.edge_planes = [ \
            euclid.Plane(p1, (p2 - p1).cross(n)) \
            for p1, p2 in map(None, points[:], points[1:] + [points[0]])
            if (p2 - p1).cross(n)] # Filter out edges that are colinear with
        # normal (non-planar polygon)

        self.point = points[0]  # An arbitrary point on this polygon

        # Axis aligned bounding box
        p1 = points[0].copy()
        p2 = points[0].copy()
        for p in points[1:]:
            if p.x < p1.x:
                p1.x = p.x
            if p.y < p1.y:
                p1.y = p.y
            if p.z < p1.z:
                p1.z = p.z
            if p.x > p2.x:
                p2.x = p.x
            if p.y > p2.y:
                p2.y = p.y
            if p.z > p2.z:
                p2.z = p.z
        self.aabbox = p1, p2
コード例 #2
0
 def __init__(self,i1,i2,i3,p1,p2,p3):
     self.vertex_indices=[i1,i2,i3];
     self.vertices=[p1,p2,p3]; #list of vertices
     self.plane=euclid.Plane(self.vertices[0],self.vertices[1],self.vertices[2]);
     self.plane.n.normalize();
     self.v1=self.vertices[1]-self.vertices[0];
     self.v2=self.vertices[2]-self.vertices[0];
コード例 #3
0
 def __init__(self,
              origin=euclid.Point3(0., 0., 0.),
              squaresize=4,
              normal=euclid.Vector3(0., 0., 1.),
              roughness=1.0,
              transparency=0.0,
              refractionIndex=1.0):
     super().__init__(color=(255, 255, 255),
                      roughness=roughness,
                      transparency=transparency,
                      refractionIndex=refractionIndex)
     self.shape = euclid.Plane(origin, normal)
     normal = normal.normalized()
     self.squaresize = squaresize
     # let's find the unit vectors
     ux = euclid.Vector3(0., 1., 0.)
     uy = euclid.Vector3(0., 0., 1.)
     un = euclid.Vector3(1., 0., 0.)  # 'original' normal
     # rotation axis
     axis = un.cross(normal)
     # cos(angle) between normal and unit normal
     angle = normal.dot(un)
     angle = math.acos(angle)
     rotation = euclid.Quaternion.new_rotate_axis(angle, axis)
     self.unitx = rotation * ux
     self.unity = rotation * uy
コード例 #4
0
    def calculateRepr(self):
        # first, reset to default values
        Ly = -self.zoom * math.tan(self.LRAngle / 2)
        Ry = -Ly
        self.L = P3(0, Ly,
                    0) - self.focus  # to leftmost point on mid row of screen
        self.R = P3(0, Ry, 0) - self.focus  # to rightmost "" ""
        self.D = V3(-1, 0, 0) * self.zoom  # line from camera to screen.
        # figure out up angle
        # first get x distance
        x = Ry * 2
        y = 1.0 / self.aspectRatio * x
        # next use trig to figure out up angle
        self.TBAngle = math.atan(y / 2 / self.zoom) * 2
        Tz = self.zoom * math.tan(self.TBAngle / 2)
        Bz = -self.zoom * math.tan(self.TBAngle / 2)
        self.T = V3(
            0, 0, Tz) - self.focus  # to topmost point on mid column of screen
        self.B = V3(0, 0, Bz) - self.focus  # to bottommost "" ""
        # screen's plane
        self.screenPlane = euclid.Plane(P3(
            0, 0, 0), self.D)  # the normal is the line from cam to screen.

        # Next, rotate all vectors accordingly.
        for i in xrange(3):
            if self.rotation[i] != 0:
                t = self.rotation[i]
                axis = V3(1 if i == 0 else 0, 1 if i == 1 else 0,
                          1 if i == 2 else 0)
                self.L = rotateGeneric(self.L, axis, t)
                self.R = rotateGeneric(self.R, axis, t)
                self.D = rotateGeneric(self.D, axis, t)
                self.T = rotateGeneric(self.T, axis, t)
                self.B = rotateGeneric(self.B, axis, t)
                self.focus = rotateGeneric(self.focus, axis, t)

        # Figure out the basic vectors for the screen.
        self.basic_horizontal = self.R - self.L
        self.basic_vertical = self.B - self.T

        # Topleft corner finding.
        self.topleft = self.focus + self.L + self.basic_vertical * .5
コード例 #5
0
def rotateGeneric(shape, k, t):
    if type(shape) == V3:
        return rotate(shape, k, t)
    if type(shape) == P3:
        v = rotate(shape, k, t)
        return P3(v.x, v.y, v.z)
    if type(shape) == R3:
        v, p = R3.v, R3.p
        out = R3(p, v)
        out.v = rotate(v, k, t)
        out.p = rotate(p, k, t)
        return out
    if type(shape) == euclid.Plane:
        n, k = shape.n, shape.k
        out = euclid.Plane(n, k)
        out.n = rotate(n, k, t)
        return out
    if type(shape) == euclid.Sphere:
        c, r = shape.c, shape.r
        out = euclid.Sphere(c, r)
        out.c = rotate(c, k, t)
        return out
    raise TypeError("Argument type for shape(" + type(shape) + ") is unknown.")