Example #1
0
File: core.py Project: geerk/ct6
 def transform(self, m):
     v = [
         tr.translate(mat([i + [1]]), self.init_p).tolist()[0][:3]
         for i in self.v
     ]
     v = [(mat([i + [1]]) * m).tolist()[0][:3] for i in v]
     self.__make_polygons(v)
Example #2
0
def rotate_ox(p, b, a):
    cosa, sina = cos(a), sin(a)
    p = translate(p, [-b[0], -b[1], -b[2]])
    p =    (mat([p + [1]]) * mat([[1,     0,    0, 0],
                                  [0,  cosa, sina, 0],
                                  [0, -sina, cosa, 0],
                                  [0,     0,    0, 1]])).tolist()[0][:3]
    return translate(p, b)
Example #3
0
def rotate_ox(m, b, a):
    cosa, sina = cos(rad(a)), sin(rad(a))
    rotm = translate(mat(1), [-b[0], -b[1], -b[2]])
    rotm = rotm * mat([[1,     0,    0, 0],
                       [0,  cosa, sina, 0],
                       [0, -sina, cosa, 0],
                       [0,     0,    0, 1]])
    rotm = rotm * translate(mat(1), b)
    return m * rotm
Example #4
0
def rotate_ox(m, b, a):
    cosa, sina = cos(rad(a)), sin(rad(a))
    rotm = translate(mat(1), [-b[0], -b[1], -b[2]])
    rotm = rotm * mat([[1,     0,    0, 0],
                       [0,  cosa, sina, 0],
                       [0, -sina, cosa, 0],
                       [0,     0,    0, 1]])
    rotm = rotm * translate(mat(1), b)
    return m * rotm
Example #5
0
def project(p, type = "ortho"):
    if type == "ortho":
        return (mat([p + [1]]) * mat([[1, 0, 0, 0],
                                      [0, 1, 0, 0],
                                      [0, 0, 0, 0],
                                      [0, 0, 0, 1]])).tolist()[0][:2]
    elif type == "oblique":
        return (mat([p + [1]]) * mat([[   1,    0, 0, 0],
                                      [   0,    1, 0, 0],
                                      [pi/4, pi/4, 0, 0],
                                      [   0,    0, 0, 1]])).tolist()[0][:2]
Example #6
0
File: core.py Project: geerk/ct6
    def setparams(self, params):
        for key in params:
            if key in ("name", "init_p"):
                exec "self.%s = params[key]" % (key,)
                continue
            if key == "mat":
                self.mat = mat(params[key])
                continue
            exec """for i in range(len(self.%s)):
                        
                        if params[key][i] == None: continue
                        if params[key][i] < 0: raise NegativeException("Parameters can't be negative")
                        self.%s[i] = params[key][i]""" % (
                key,
                key,
            )

        if self.cylM[1] > self.cylN[0]:
            raise BadRadiusException("Radius cyl M must be less then radius cyl N")
        if self.cylD[0] > self.cylF[0]:
            raise BadRadiusException("Radius cyl D must be less then radius cyl F")
        if self.cylF[0] > self.cylH[0]:
            raise BadRadiusException("Radius cyl F must be less then radius cyl H")
        if self.mat == mat(1):
            self.mat = tr.translate(self.mat, self.init_p)
        self.namesofshapes = (
            "cylA",
            "coneB",
            "coneC",
            "cylD",
            "cylE",
            "cylF",
            "cylG",
            "cylH",
            "coneI",
            "cylJ",
            "coneK",
            "cylL",
            "cylM",
            "cylN",
        )
        self.c = self.init_p[:]
        # calculating base point (for rotation, scaling, etc.)
        for j in [getattr(self, i)[2] for i in self.namesofshapes]:
            self.c[2] += j / 2.0

        tmp_init_p = [0, 0, 0]
        for name in self.namesofshapes:
            sh = getattr(self, name)[:]
            maxr = sqrt((tmp_init_p[2] - self.c[2]) ** 2 + (sh[0] > sh[1] and sh[0] or sh[1]) ** 2)  # may cause bug
            self.max_radius = maxr > self.max_radius and maxr or self.max_radius  # may cause bug
            self.shapes[name] = Cone(tmp_init_p[:], getattr(self, name))
            tmp_init_p[2] += getattr(self, name)[2]
Example #7
0
def main(m, n):

    from matrix import mat, show

    M = mat(m, n)
    partial(M, m, n)
    print(show(M), end="")
Example #8
0
def grid ( m , n ) :

	e = mat( m + 1 , n + 1 , None )

	e[0][0] = 1

	return e
Example #9
0
def main ( m , n ) :

	from matrix import mat , show

	M = mat( m , n )
	info( M , m , n )
	print( show( M ) , end = "" )
Example #10
0
def camat((ox, oy, oz)):
    cosa, sina = cos(rad(-oz)), sin(rad(-oz))
    cosb, sinb = cos(rad(-oy)), sin(rad(-oy))
    cosc, sinc = cos(rad(-ox)), sin(rad(-ox))
    mat_oz = mat([[ cosa, sina, 0, 0],
                       [-sina, cosa, 0, 0],
                       [    0,    0, 1, 0],
                       [    0,    0, 0, 1]])
    mat_oy = mat([[cosb, 0, -sinb, 0],
                       [   0, 1,     0, 0],
                       [sinb, 0,  cosb, 0],
                       [   0, 0,     0, 1]])
    mat_ox = mat([[1,     0,    0, 0],
                       [0,  cosc, sinc, 0],
                       [0, -sinc, cosc, 0],
                       [0,     0,    0, 1]])
    return (mat_oz, mat_oy, mat_ox)
Example #11
0
File: core.py Project: geerk/ct6
    def setparams(self, params):
        for key in params:
            if key in ('name', 'init_p'):
                exec 'self.%s = params[key]' % (key, )
                continue
            if key == 'mat':
                self.mat = mat(params[key])
                continue
            exec """for i in range(len(self.%s)):
                        
                        if params[key][i] == None: continue
                        if params[key][i] < 0: raise NegativeException("Parameters can't be negative")
                        self.%s[i] = params[key][i]""" % (key, key)

        if self.cylM[1] > self.cylN[0]:
            raise BadRadiusException(
                'Radius cyl M must be less then radius cyl N')
        if self.cylD[0] > self.cylF[0]:
            raise BadRadiusException(
                'Radius cyl D must be less then radius cyl F')
        if self.cylF[0] > self.cylH[0]:
            raise BadRadiusException(
                'Radius cyl F must be less then radius cyl H')
        if self.mat == mat(1): self.mat = tr.translate(self.mat, self.init_p)
        self.namesofshapes = ('cylA', 'coneB', 'coneC', 'cylD', 'cylE', 'cylF',
                              'cylG', 'cylH', 'coneI', 'cylJ', 'coneK', 'cylL',
                              'cylM', 'cylN')
        self.c = self.init_p[:]
        #calculating base point (for rotation, scaling, etc.)
        for j in [getattr(self, i)[2] for i in self.namesofshapes]:
            self.c[2] += j / 2.0

        tmp_init_p = [0, 0, 0]
        for name in self.namesofshapes:
            sh = getattr(self, name)[:]
            maxr = sqrt((tmp_init_p[2] - self.c[2])**2 +
                        (sh[0] > sh[1] and sh[0] or sh[1])**2)  #may cause bug
            self.max_radius = maxr > self.max_radius and maxr or self.max_radius  #may cause bug
            self.shapes[name] = Cone(tmp_init_p[:], getattr(self, name))
            tmp_init_p[2] += getattr(self, name)[2]
Example #12
0
def grid(m, n):

    e = mat(m + 1, n + 1, [])

    e[0][0] = [[]]

    for i in range(1, m + 1):

        e[i][0] = [["a[%d]" % k for k in range(1, i + 1)]]

    for j in range(1, n + 1):

        e[0][j] = [["b[%d]" % k for k in range(1, j + 1)]]

    return e
Example #13
0
def compute ( compare , m , n ) :

	Mo = mat( m , m )

	mohanty( compare , Mo , m , n )

	print( "mohanty matrix" )
	print( show( Mo ) , end = "" )

	d = det( Mo , m )

	print( "after gaussian elimination" )
	print( show( Mo ) , end = "" )

	return d
Example #14
0
def compute(compare, m, n):

    Mo = mat(m, m)

    mohanty(compare, Mo, m, n)

    print("mohanty matrix")
    print(show(Mo), end="")

    d = det(Mo, m)

    print("after gaussian elimination")
    print(show(Mo), end="")

    return d
Example #15
0
def grid ( m , n ) :

	e = mat( m + 1 , n + 1 , [ ] )

	e[0][0] = [ [ ] ]

	for i in range ( 1 , m + 1 ) :

		e[i][0] = [ [ "a[%d]" % k for k in range( 1 , i + 1 ) ] ]

	for j in range ( 1 , n + 1 ) :

		e[0][j] = [ [ "b[%d]" % k for k in range( 1 , j + 1 ) ] ]

	return e
Example #16
0
File: core.py Project: geerk/ct6
    def __init__(self, **kwargs):
        self.name = 'obj'
        self.init_p = [0, 0, 0]
        self.cylA = [10, 10, 5]
        self.coneB = [10, 30, 40]
        self.coneC = [30, 10, 40]
        self.cylD = [15, 15, 5]
        self.cylE = [10, 10, 15]
        self.cylF = [30, 30, 10]
        self.cylG = [10, 10, 5]
        self.cylH = [50, 50, 10]
        self.coneI = [10, 30, 100]
        self.cylJ = [40, 40, 20]
        self.coneK = [40, 70, 40]
        self.cylL = [70, 70, 5]
        self.cylM = [65, 65, 5]
        self.cylN = [70, 70, 10]
        self.mat = mat(1)

        self.state = 'visible'
        self.c = []
        self.shapes = {}
        self.max_radius = 0
        self.setparams(kwargs)
Example #17
0
File: core.py Project: geerk/ct6
 def __init__(self, **kwargs):
     self.pos = kwargs['pos'][:]
     self.dir_ = kwargs['dir_'][:]
     self.near_clip_z = kwargs['near_clip_z']
     self.far_clip_z = kwargs['far_clip_z']
     self.viewport_width = kwargs['viewport_width']
     self.viewport_height = kwargs['viewport_height']
     self.viewport_center_x = (self.viewport_width - 1) / 2
     self.viewport_center_y = (self.viewport_height - 1) / 2
     self.aspect_ratio = float(self.viewport_width) / float(
         self.viewport_height)
     if kwargs.has_key('mcam'): self.mcam = kwargs['mcam']
     else: self.mcam = mat(1)
     self.fov = kwargs['fov']
     self.viewplane_width = 2.0
     self.viewplane_height = 2.0 / self.aspect_ratio
     self.view_dist = 0.5 * self.viewplane_width * tan(rad(self.fov / 2.0))
     #init mcam:
     self.mcam = tr.translate(self.mcam,
                              (-self.pos[0], -self.pos[1], -self.pos[2]))
     (mat_oz, mat_oy, mat_ox) = tr.camat(self.dir_)
     self.mcam = self.mcam * mat_oz
     self.mcam = self.mcam * mat_oy
     self.mcam = self.mcam * mat_ox
Example #18
0
File: core.py Project: geerk/ct6
    def __init__(self, **kwargs):
        self.name = "obj"
        self.init_p = [0, 0, 0]
        self.cylA = [10, 10, 5]
        self.coneB = [10, 30, 40]
        self.coneC = [30, 10, 40]
        self.cylD = [15, 15, 5]
        self.cylE = [10, 10, 15]
        self.cylF = [30, 30, 10]
        self.cylG = [10, 10, 5]
        self.cylH = [50, 50, 10]
        self.coneI = [10, 30, 100]
        self.cylJ = [40, 40, 20]
        self.coneK = [40, 70, 40]
        self.cylL = [70, 70, 5]
        self.cylM = [65, 65, 5]
        self.cylN = [70, 70, 10]
        self.mat = mat(1)

        self.state = "visible"
        self.c = []
        self.shapes = {}
        self.max_radius = 0
        self.setparams(kwargs)
Example #19
0
File: core.py Project: geerk/ct6
 def __init__(self, **kwargs):
     self.pos = kwargs["pos"][:]
     self.dir_ = kwargs["dir_"][:]
     self.near_clip_z = kwargs["near_clip_z"]
     self.far_clip_z = kwargs["far_clip_z"]
     self.viewport_width = kwargs["viewport_width"]
     self.viewport_height = kwargs["viewport_height"]
     self.viewport_center_x = (self.viewport_width - 1) / 2
     self.viewport_center_y = (self.viewport_height - 1) / 2
     self.aspect_ratio = float(self.viewport_width) / float(self.viewport_height)
     if kwargs.has_key("mcam"):
         self.mcam = kwargs["mcam"]
     else:
         self.mcam = mat(1)
     self.fov = kwargs["fov"]
     self.viewplane_width = 2.0
     self.viewplane_height = 2.0 / self.aspect_ratio
     self.view_dist = 0.5 * self.viewplane_width * tan(rad(self.fov / 2.0))
     # init mcam:
     self.mcam = tr.translate(self.mcam, (-self.pos[0], -self.pos[1], -self.pos[2]))
     (mat_oz, mat_oy, mat_ox) = tr.camat(self.dir_)
     self.mcam = self.mcam * mat_oz
     self.mcam = self.mcam * mat_oy
     self.mcam = self.mcam * mat_ox
Example #20
0
File: core.py Project: geerk/ct6
 def world2cam(self, v):
     return (mat([v + [1]]) * self.mcam).tolist()[0][:3]
Example #21
0
import time
import numpy as np
import cv2
from collections import defaultdict
import destination
import path
#import direction
import matrix
x1 = int(input("Enter starting point: "))
y1 = int(input("Enter the y coordinate: "))
#dir=input("Enter direction: ")
flag = 1
sh = input("Enter shape: ")
co = input("Enter color: ")
s = (x1, y1)
a = (matrix.mat())
print(a)
if (x1 == 4 and y1 == 0):
    dir = 'u'
    a[3][4][0:2] = a[4][5][0:2] = a[5][4][0:2] = [0, 0]
elif (x1 == 0 and y1 == 4):
    dir = 'r'
    a[4][3][0:2] = a[4][5][0:2] = a[5][4][0:2] = [0, 0]
elif (x1 == 4 and y1 == 8):
    dir = 'd'
    a[3][4][0:2] = a[4][3][0:2] = a[5][4][0:2] = [0, 0]
elif (x1 == 8 and y1 == 4):
    dir = 'l'
    a[3][4][0:2] = a[4][5][0:2] = a[4][3][0:2] = [0, 0]
while (True):
    points = []
Example #22
0
def scale(p, b, sx, sy, sz):
    return translate((mat([translate(p, [-b[0], -b[1], -b[2]]) + [1]]) * 
                      mat([[sx,  0,  0, 0],
                           [ 0, sy,  0, 0],
                           [ 0,  0, sz, 0],
                           [ 0,  0,  0, 1]])).tolist()[0][:3], b)
Example #23
0
File: core.py Project: geerk/ct6
 def world2cam(self, v):
     return (mat([v + [1]]) * self.mcam).tolist()[0][:3]
Example #24
0
File: core.py Project: geerk/ct6
 def transform(self, m):
     v = [tr.translate(mat([i + [1]]), self.init_p).tolist()[0][:3] for i in self.v]
     v = [(mat([i + [1]]) * m).tolist()[0][:3] for i in v]
     self.__make_polygons(v)
Example #25
0
File: core.py Project: geerk/ct6
 def get_c(self):
     return (mat([self.c[:] + [1]]) * self.mat).tolist()[0][:3]
Example #26
0
def main(m, n):

    from matrix import mat, show

    M = mat(m, n, 0)
    print(show(M), end="")
Example #27
0
def translate(m, x_y_z):
    x, y, z = x_y_z
    return m * mat([[1, 0, 0, 0],
                    [0, 1, 0, 0],
                    [0, 0, 1, 0],
                    [x, y, z, 1]])
Example #28
0
from matrix import matrix as mat

def project(p, type = "ortho"):
    if type == "ortho":
        return (mat([p + [1]]) * mat([[1, 0, 0, 0],
                                      [0, 1, 0, 0],
                                      [0, 0, 0, 0],
                                      [0, 0, 0, 1]])).tolist()[0][:2]
    elif type == "oblique":
        return (mat([p + [1]]) * mat([[   1,    0, 0, 0],
                                      [   0,    1, 0, 0],
                                      [pi/4, pi/4, 0, 0],
                                      [   0,    0, 0, 1]])).tolist()[0][:2]

def translate(p, (m, n, l)):
    return (mat([p + [1]]) * mat([[1, 0, 0, 0],
                                  [0, 1, 0, 0],
                                  [0, 0, 1, 0],
                                  [m, n, l, 1]])).tolist()[0][:3]

def rotate_oz(p, b, a):
    cosa, sina = cos(a), sin(a)
    p = translate(p, [-b[0], -b[1], -b[2]])
    p =    (mat([p + [1]]) * mat([[ cosa, sina, 0, 0],
                                  [-sina, cosa, 0, 0],
                                  [    0,    0, 1, 0],
                                  [    0,    0, 0, 1]])).tolist()[0][:3]
    return translate(p, b)
    
def rotate_oy(p, b, a):
    cosa, sina = cos(a), sin(a)
Example #29
0
File: core.py Project: geerk/ct6
 def get_c(self):
     return (mat([self.c[:] + [1]]) * self.mat).tolist()[0][:3]
Example #30
0
                       [   0, 0,     0, 1]])
    mat_ox = mat([[1,     0,    0, 0],
                       [0,  cosc, sinc, 0],
                       [0, -sinc, cosc, 0],
                       [0,     0,    0, 1]])
    return (mat_oz, mat_oy, mat_ox)

def project(p, prtype, c = 1000.0):
    if prtype == "parallel":
        return [p[0], p[1]]
    elif prtype == "central":
        return [p[0]/(1 - p[2] / c), p[1]/(1 - p[2] / c)]

def translate(m, (x, y, z)):
    return m * mat([[1, 0, 0, 0],
                    [0, 1, 0, 0],
                    [0, 0, 1, 0],
                    [x, y, z, 1]])

def rotate(m, b, (ox, oy, oz)):
    return rotate_oz(rotate_oy(rotate_ox(m, b, ox), b, oy), b, oz)

def rotate_oz(m, b, a):
    cosa, sina = cos(rad(a)), sin(rad(a))
    rotm = translate(mat(1), [-b[0], -b[1], -b[2]])
    rotm = rotm * mat([[ cosa, sina, 0, 0],
                       [-sina, cosa, 0, 0],
                       [    0,    0, 1, 0],
                       [    0,    0, 0, 1]])
    rotm = rotm * translate(mat(1), b)
    return m * rotm