-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderAlgorithm.py
More file actions
57 lines (51 loc) · 1.89 KB
/
renderAlgorithm.py
File metadata and controls
57 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import math
def getCommandLines(txt):
str_command = txt.split('\n');
return str_command
def getCommandTitle(cmd):
title = cmd.split(' ')[0]
return title
def renderOnce(win, txt):
commands = getCommandLines(txt)
for cmd in commands:
title = getCommandTitle(cmd)
if title == '#domain:':
win.domain(cmd)
if title == '#sphere:':
win.sphere(cmd)
if title == '#cylinder:':
win.cyliner(cmd)
# if title == '#plate:':
# win.plane(cmd)
if title == '#box:':
win.box(cmd)
# if title == '#triangle:':
# win.triangle(cmd)
# if title == '#cone:':
# win.cone(cmd)
def CalculateAngle(xMin, xMax, yMin, yMax, zMin, zMax):
vector = [xMax - xMin, yMax - yMin, zMax - zMin]
angleX = math.atan2(vector[1], vector[0])
angleX = angleX*180/math.pi
angleY = 180 - angleX
angleZ = math.atan2(vector[2], math.sqrt((vector[0]**2 + vector[1]**2)))
angleZ = angleZ*180/math.pi
return angleX, angleY, angleZ
def CalculateMovement(axisX, axisY, axisZ, angleX, angleY, angleZ):
# rotate around x axis
moveY = axisY*math.cos(angleX * math.pi / 180) - axisZ*math.sin(angleX * math.pi / 180)
moveZ = axisY*math.sin(angleX * math.pi / 180) + axisZ*math.cos(angleX * math.pi / 180)
axisY = moveY
axisZ = moveZ
# rotate around y axis
moveX = axisX*math.cos(angleY * math.pi / 180) + axisZ*math.sin(angleY * math.pi / 180)
moveZ = -axisX*math.sin(angleY * math.pi / 180) + axisZ*math.cos(angleY * math.pi / 180)
axisX = moveX
axisZ = moveZ
# rotate around z axis
moveX = axisX*math.cos(angleZ * math.pi / 180) - axisY*math.sin(angleZ * math.pi / 180)
moveY = axisX*math.sin(angleZ * math.pi / 180) + axisY*math.cos(angleZ * math.pi / 180)
axisX = moveX
axisY = moveY
return axisX, axisY, axisZ