I am using a combination of a rotation matrices, weak perspective equations, and a custom turtle wrapper to make a 3D turtle wrapper (It's a toy project to see if I can do it 3D without numpy and also using turtle)
To clarify, so I don't have to copy and paste the code, pix(point, update)
stamps a small square turtle on the screen to show a vertex. setup()
makes it tracer(0,0)
, and then shapesize(1 / 20, 1 / 20)
, ht
and finally penup()
refresh() just uses update()
Here it is:
def vertdata(crt): #CRT stands for Coord-Rotation-Transformation. I took
#transformation out for now, because those values are 0
#for this example.
vert = [crt[0][0],crt[0][1],crt[0][2]]
rotation = [crt[1][0],crt[1][1],crt[1][2]]
return rotate(vert, rotation)
def vertex(point, upd):
data = vertdata(point)
pix([((data[0] * 2) / ((data[2] / 15) - 15) * 10), ((data[1] * 2) / ((data[2] / 15) - 15) * 10)], upd)
setup(100, 1000, 1000)
for x in range(3600):
clear()
vertex(
[[10,-10,10],
[45,45,x]],
False
)
vertex(
[[-10,-10,10],
[45,45,x]],
False
)
vertex(
[[10,10,10],
[45,45,x]],
False
)
vertex(
[[-10,10,10],
[45,45,x]],
False
)
vertex(
[[10,-10,-10],
[45,45,x]],
False
)
vertex(
[[-10,-10,-10],
[45,45,x]],
False
)
vertex(
[[10,10,-10],
[45,45,x]],
False
)
vertex(
[[-10,10,-10],
[45,45,x]],
False
)
refresh()
#Sorry about the long code. I don't really think I can simplify this any more.
What's the problem? Rotation on the Z axis is distorted. The cube stretches and deforms. A long time ago, I did the same thing in scratch (a loooooonggg time ago) and I took those equations and typed them into python because I knew they worked. (So yes, they work) I can't spot the problem, maybe one of you can? This is kind of my last resort. Here's a picture to help. Sorry, I'm on mobile now because I no longer have access to the computer, so I can't give a picture of the distortion.
My guess is a typo, but I can't find one.