3d - Fast method to rasterize triangle in python -



3d - Fast method to rasterize triangle in python -

in python want rasterize 2d triangle 3d triangle fast possible , clip pixels out of z bounds. can convert 3d coordinates 2d, can't seem rasterizing working. i'm using set pixel method takes (x,y,colour) , (0,0) @ top left.

thanks help. triangle code used.

def triangle(self,v = vec2(0,0),v1 = vec2(0,0),v2 = vec2(0,0), colour = 0xffffff): sort = sortvecbyy(v,v1,v2) = sort[0] b = sort[1] c = sort[2] if b.y == c.y: self.flatbottomtri(a,b,c,colour) elif a.y == b.y: self.flattoptri(a,b,c,colour) else: d = vec2(int(a.x + (float((b.y-a.y)/(c.y-a.y))) * (c.x - a.x)),b.y) self.flatbottomtri(a,b,d,colour) self.flattoptri(b,d,c,colour) def flatbottomtri(self,v1,v2,v3,colour): r1 = (v2.y - v1.y) s1 = 0 if r1 != 0.0: s1 = (v2.x - v1.x) / r1 r2 = (v3.y - v1.y) s2 = 0 if r2 != 0.0: s2 = (v3.x - v1.x) / (v3.y - v1.y) x1 = v1.x x2 = v1.x + 0.5 sy in range(v1.y,v2.y): x in range(int(x1),int(x2)): self.set(x,sy,colour) x1 += s1 x2 += s2 def flattoptri(self,v1,v2,v3,colour): s1 = (v3.x - v1.x) / (v3.y - v1.y) s2 = (v3.x - v2.x) / (v3.y - v2.y) x1 = v3.x x2 = v3.x + 0.5 sy in range(v3.y,v1.y,-1): x1 -= s1 x2 -= s2 x in range(int(x1),int(x2)): self.set(x,sy,colour)

python 3d geometry 2d rasterizing

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -