def getTrinagles(): f = open('result.txt') triangles = [] for line in f.readlines(): triangles.append([ float(point) for point in line.replace('[', '').replace(']', '').split(',') ]) newtriangle = [] for triangle in triangles: point1 = gr.Point3d(*triangle[0:3]) # point1.scale(scalex, scaley, scalez) point2 = gr.Point3d(*triangle[3:6]) # point2.scale(scalex, scaley, scalez) point3 = gr.Point3d(*triangle[6:9]) # point3.scale(scalex, scaley, scalez) newtriangle.append(gr.Triangle(point1, point2, point3)) return newtriangle
import vector as v import triangle as t import math a = t.Point3d(-3, 2, 1) b = t.Point3d(-1, 2, 4) c = t.Point3d(3, 3, -1) tr = t.Triangle(b, c, a) coef = tr.getEquation() print(coef) print(c.x * coef[0] + c.y * coef[1] + c.z * coef[2] + coef[3]) # a = v.Vector.createVector(2, 0, 5) # b = v.Vector.createVector(6, 1, 0) # print(v.Vector.vectorMultiply(a, b)) # a = triangle.Point3d(0, 0, 0) # b = triangle.Point3d(0, 0, 100) # c = triangle.Point3d(0, 100, 0) # # tr = triangle.Triangle(a, b, c) # normal = tr.getNormal() # print(normal) # LIGHT_VECTOR = vector.Vector(0, 0, 10) # angle = vector.cosOfAngle(normal, LIGHT_VECTOR) # print(angle)
def getTrinagles(): global MINIY, MAXIY, MINIX, MINIY, MINIZ, MAXIZ, MIDDLPOINT f = open('result.txt') triangles = [] MINIY = inf MAXIY = -inf MINIX = inf MAXIX = -inf MINIZ = inf MAXIZ = -inf for line in f.readlines(): triangles.append([ (float(point)) for point in line.replace('[', '').replace(']', '').split(',') ]) newtriangle = [] big = 20 #110 reg = 20 #35 for triangle in triangles: MAXIX = max(MAXIX, triangle[0], triangle[3], triangle[6]) MINIX = min(MINIX, triangle[0], triangle[3], triangle[6]) MAXIY = max(MAXIY, triangle[1], triangle[4], triangle[7]) MINIY = min(MINIY, triangle[1], triangle[4], triangle[7]) MAXIZ = max(MAXIZ, triangle[2], triangle[5], triangle[8]) MINIZ = min(MINIZ, triangle[2], triangle[5], triangle[8]) xmultiplier = (SCREEN_WIDTH / 1.7) / max(abs(MINIX), abs(MAXIX)) ymultiplier = (SCREEN_HEIGHT / 3) / max(abs(MINIY), abs(MAXIY)) zmultiplier = (SCREEN_HEIGHT / 3) / max(abs(MINIZ), abs(MAXIZ)) # #This is stable # MINIY *= xmultiplier # MAXIY *= xmultiplier # MAXIX *= xmultiplier # MINIX *= xmultiplier # MAXIZ *= xmultiplier # MINIZ *= xmultiplier MINIY *= ymultiplier MAXIY *= ymultiplier MAXIX *= xmultiplier MINIX *= xmultiplier MAXIZ *= zmultiplier MINIZ *= zmultiplier MIDDLPOINT = tr.Point3d((MINIX + MAXIX) / 2, (MINIY + MAXIY) / 2, (MINIZ + MAXIZ) / 2) MIDDLPOINT.move(-SCREEN_WIDTH / 2.5, -SCREEN_HEIGHT / 5, 0) MINIY -= SCREEN_HEIGHT / 4 MAXIY -= SCREEN_HEIGHT / 4 for triangle in triangles: # #This is stable # triangle[0] *= xmultiplier # triangle[1] *= xmultiplier # triangle[2] *= xmultiplier # triangle[3] *= xmultiplier # triangle[4] *= xmultiplier # triangle[5] *= xmultiplier # triangle[6] *= xmultiplier # triangle[7] *= xmultiplier triangle[0] *= xmultiplier triangle[1] *= ymultiplier triangle[2] *= zmultiplier triangle[3] *= xmultiplier triangle[4] *= ymultiplier triangle[5] *= zmultiplier triangle[6] *= xmultiplier triangle[7] *= ymultiplier triangle[8] *= zmultiplier for i in range(len(triangle)): triangle[i] = floor(triangle[i]) point1 = tr.Point3d(*triangle[0:3]) point2 = tr.Point3d(*triangle[3:6]) point3 = tr.Point3d(*triangle[6:9]) newitem = tr.Triangle(point1, point2, point3) newitem.move(-SCREEN_WIDTH / 2.5, -SCREEN_HEIGHT / 5, 0) newtriangle.append(newitem) return newtriangle
def changeLightPoint(self, x, y, z): self.lightpoint = tr.Point3d(x, y, z)
from PyQt5.QtGui import QPainter, QColor, QPen, QPixmap, QBitmap, QImage, QPaintEvent from PyQt5.QtCore import Qt import triangle as tr from vector import Vector, cosOfAngle from math import ceil, floor, inf, acos, pi, sqrt SCREEN_WIDTH = 600 SCREEN_HEIGHT = 600 MINIX = None MAXIX = None MINIY = None MAXIY = None MAXIZ = None MINIZ = None MIDDLPOINT = None LIGHTPOINT = tr.Point3d(100, 700, 100) def getTrinagles(): global MINIY, MAXIY, MINIX, MINIY, MINIZ, MAXIZ, MIDDLPOINT f = open('result.txt') triangles = [] MINIY = inf MAXIY = -inf MINIX = inf MAXIX = -inf MINIZ = inf MAXIZ = -inf for line in f.readlines(): triangles.append([ (float(point))
def myDrawLine(self, qp: QPainter, a: gr.Point3d, b: gr.Point3d): atmp = gr.Point3d(a.x + (self.width() // 2), -a.y + (self.height() // 2), a.z) btmp = gr.Point3d(b.x + (self.width() // 2), -b.y + (self.height() // 2), b.z) qp.drawLine(atmp.x, atmp.y, btmp.x, btmp.y)