Mesh: Apply clang-format
This commit is contained in:
@@ -15,7 +15,8 @@ Sample code for creating a mesh:
|
||||
|
||||
import math
|
||||
|
||||
def Sphere (radius, count):
|
||||
|
||||
def Sphere(radius, count):
|
||||
"""Creates a sphere with a given radius.
|
||||
|
||||
bla bla bla
|
||||
@@ -23,11 +24,12 @@ def Sphere (radius, count):
|
||||
"""
|
||||
return Ellipsoid(radius, radius, count)
|
||||
|
||||
def Ellipsoid (lenX, lenY, count):
|
||||
|
||||
def Ellipsoid(lenX, lenY, count):
|
||||
polyline = []
|
||||
step = math.pi / count
|
||||
i = 0.0
|
||||
while (i < math.pi + step / 10.0):
|
||||
while i < math.pi + step / 10.0:
|
||||
x = math.cos(i) * lenX
|
||||
y = math.sin(i) * lenY
|
||||
polyline.append([x, y])
|
||||
@@ -35,53 +37,56 @@ def Ellipsoid (lenX, lenY, count):
|
||||
|
||||
return RotationBody(polyline, count)
|
||||
|
||||
def Cylinder (radius, len, closed, edgelen, count):
|
||||
|
||||
def Cylinder(radius, len, closed, edgelen, count):
|
||||
return Cone(radius, radius, len, closed, edgelen, count)
|
||||
|
||||
def Cone (radius1, radius2, len, closed, edgelen, count):
|
||||
|
||||
def Cone(radius1, radius2, len, closed, edgelen, count):
|
||||
polyline = []
|
||||
if (closed):
|
||||
if closed:
|
||||
try:
|
||||
step = radius2 / math.ceil(radius2 / edgelen)
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
else:
|
||||
i = 0.0
|
||||
while (i < radius2 - step / 2.0):
|
||||
while i < radius2 - step / 2.0:
|
||||
polyline.append([len, i])
|
||||
i = i + step
|
||||
|
||||
ct = math.ceil(len / edgelen)
|
||||
step = len / ct
|
||||
rstep = (radius1 - radius2) / ct
|
||||
i = len;
|
||||
i = len
|
||||
r = radius2
|
||||
while (i > 0.0 + step / 2.0):
|
||||
while i > 0.0 + step / 2.0:
|
||||
polyline.append([i, r])
|
||||
i = i - step
|
||||
r = r + rstep
|
||||
polyline.append([0.0, radius1])
|
||||
|
||||
if (closed):
|
||||
if closed:
|
||||
try:
|
||||
step = radius1 / math.ceil(radius1 / edgelen)
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
else:
|
||||
i = radius1 - step
|
||||
while (i > 0.0 + step / 2.0):
|
||||
while i > 0.0 + step / 2.0:
|
||||
polyline.append([0.0, i])
|
||||
i = i - step
|
||||
polyline.append([0.0, 0.0])
|
||||
|
||||
return RotationBody(polyline, count)
|
||||
|
||||
def Toroid (radius1, radius2, count):
|
||||
|
||||
def Toroid(radius1, radius2, count):
|
||||
polyline = []
|
||||
|
||||
step = math.pi * 2.0 / count
|
||||
i = -math.pi
|
||||
while (i < math.pi + step / 10.0):
|
||||
while i < math.pi + step / 10.0:
|
||||
x = radius1 + math.cos(i) * radius2
|
||||
y = radius1 + math.sin(i) * radius2
|
||||
polyline.append([x, y])
|
||||
@@ -90,7 +95,7 @@ def Toroid (radius1, radius2, count):
|
||||
return RotationBody(polyline, count)
|
||||
|
||||
|
||||
def RotationBody (polyline, count):
|
||||
def RotationBody(polyline, count):
|
||||
"""Build a rotation body from a given (closed) polyline, rotation axis is the X-Axis.
|
||||
|
||||
Parameter: polyline: list of tuple of 2 floats (2d vector)
|
||||
@@ -99,12 +104,12 @@ def RotationBody (polyline, count):
|
||||
facets = []
|
||||
|
||||
step = math.pi * 2.0 / count
|
||||
i = -math.pi;
|
||||
while (i < math.pi - step / 10.0):
|
||||
i = -math.pi
|
||||
while i < math.pi - step / 10.0:
|
||||
li = i + step
|
||||
for j in range(0, len(polyline) - 1):
|
||||
v1 = polyline[j]
|
||||
v2 = polyline[j+1]
|
||||
v2 = polyline[j + 1]
|
||||
|
||||
x1 = v1[0]
|
||||
y1 = v1[1] * math.cos(i)
|
||||
@@ -119,21 +124,22 @@ def RotationBody (polyline, count):
|
||||
y4 = v2[1] * math.cos(li)
|
||||
z4 = v2[1] * math.sin(li)
|
||||
|
||||
if (v1[1] != 0.0):
|
||||
if v1[1] != 0.0:
|
||||
facets.append([x1, y1, z1])
|
||||
facets.append([x2, y2, z2])
|
||||
facets.append([x3, y3, z3])
|
||||
|
||||
if (v2[1] != 0.0):
|
||||
if v2[1] != 0.0:
|
||||
facets.append([x2, y2, z2])
|
||||
facets.append([x4, y4, z4])
|
||||
facets.append([x3, y3, z3])
|
||||
|
||||
i = i + step
|
||||
|
||||
return facets;
|
||||
return facets
|
||||
|
||||
def Cube (lenX, lenY, lenZ):
|
||||
|
||||
def Cube(lenX, lenY, lenZ):
|
||||
hx = lenX / 2.0
|
||||
hy = lenY / 2.0
|
||||
hz = lenZ / 2.0
|
||||
@@ -190,80 +196,83 @@ def Cube (lenX, lenY, lenZ):
|
||||
|
||||
return facets
|
||||
|
||||
def FineCube (lenX, lenY, lenZ, edgelen):
|
||||
|
||||
def FineCube(lenX, lenY, lenZ, edgelen):
|
||||
hx = lenX / 2.0
|
||||
hy = lenY / 2.0
|
||||
hz = lenZ / 2.0
|
||||
cx = int(max(lenX / edgelen,1))
|
||||
cx = int(max(lenX / edgelen, 1))
|
||||
dx = lenX / cx
|
||||
cy = int(max(lenY / edgelen,1))
|
||||
cy = int(max(lenY / edgelen, 1))
|
||||
dy = lenY / cy
|
||||
cz = int(max(lenZ / edgelen,1))
|
||||
cz = int(max(lenZ / edgelen, 1))
|
||||
dz = lenZ / cz
|
||||
|
||||
facets = []
|
||||
|
||||
# z
|
||||
for i in range(0,cx):
|
||||
for j in range(0,cy):
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, -hz])
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+1)*dy, -hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, -hz])
|
||||
for i in range(0, cx):
|
||||
for j in range(0, cy):
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, -hz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 1) * dy, -hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, -hz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, -hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, -hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+0)*dy, -hz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, -hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, -hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 0) * dy, -hz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, hz])
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+1)*dy, hz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, hz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 1) * dy, hz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, -hy+(j+0)*dy, hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+0)*dy, hz])
|
||||
facets.append([-hx+(i+1)*dx, -hy+(j+1)*dy, hz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy + (j + 0) * dy, hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 0) * dy, hz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy + (j + 1) * dy, hz])
|
||||
|
||||
# y
|
||||
for i in range(0,cx):
|
||||
for j in range(0,cz):
|
||||
facets.append([-hx+(i+0)*dx, -hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx+(i+1)*dx, -hy, -hz+(j+1)*dz])
|
||||
facets.append([-hx+(i+0)*dx, -hy, -hz+(j+1)*dz])
|
||||
for i in range(0, cx):
|
||||
for j in range(0, cz):
|
||||
facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 1) * dz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 1) * dz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, -hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx+(i+1)*dx, -hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx+(i+1)*dx, -hy, -hz+(j+1)*dz])
|
||||
facets.append([-hx + (i + 0) * dx, -hy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, -hy, -hz + (j + 1) * dz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx+(i+0)*dx, hy, -hz+(j+1)*dz])
|
||||
facets.append([-hx+(i+1)*dx, hy, -hz+(j+1)*dz])
|
||||
facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 1) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 1) * dz])
|
||||
|
||||
facets.append([-hx+(i+0)*dx, hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx+(i+1)*dx, hy, -hz+(j+1)*dz])
|
||||
facets.append([-hx+(i+1)*dx, hy, -hz+(j+0)*dz])
|
||||
facets.append([-hx + (i + 0) * dx, hy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 1) * dz])
|
||||
facets.append([-hx + (i + 1) * dx, hy, -hz + (j + 0) * dz])
|
||||
|
||||
# x
|
||||
for i in range(0,cy):
|
||||
for j in range(0,cz):
|
||||
facets.append([-hx, -hy+(i+0)*dy, -hz+(j+0)*dz])
|
||||
facets.append([-hx, -hy+(i+0)*dy, -hz+(j+1)*dz])
|
||||
facets.append([-hx, -hy+(i+1)*dy, -hz+(j+1)*dz])
|
||||
for i in range(0, cy):
|
||||
for j in range(0, cz):
|
||||
facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 1) * dz])
|
||||
facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz])
|
||||
|
||||
facets.append([-hx, -hy+(i+0)*dy, -hz+(j+0)*dz])
|
||||
facets.append([-hx, -hy+(i+1)*dy, -hz+(j+1)*dz])
|
||||
facets.append([-hx, -hy+(i+1)*dy, -hz+(j+0)*dz])
|
||||
facets.append([-hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz])
|
||||
facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz])
|
||||
facets.append([-hx, -hy + (i + 1) * dy, -hz + (j + 0) * dz])
|
||||
|
||||
facets.append([hx, -hy+(i+0)*dy, -hz+(j+0)*dz])
|
||||
facets.append([hx, -hy+(i+1)*dy, -hz+(j+1)*dz])
|
||||
facets.append([hx, -hy+(i+0)*dy, -hz+(j+1)*dz])
|
||||
facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz])
|
||||
facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz])
|
||||
facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 1) * dz])
|
||||
|
||||
facets.append([hx, -hy+(i+0)*dy, -hz+(j+0)*dz])
|
||||
facets.append([hx, -hy+(i+1)*dy, -hz+(j+0)*dz])
|
||||
facets.append([hx, -hy+(i+1)*dy, -hz+(j+1)*dz])
|
||||
facets.append([hx, -hy + (i + 0) * dy, -hz + (j + 0) * dz])
|
||||
facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 0) * dz])
|
||||
facets.append([hx, -hy + (i + 1) * dy, -hz + (j + 1) * dz])
|
||||
|
||||
return facets
|
||||
|
||||
def main ():
|
||||
Cylinder (10.0, 20.0, 1, 10, 10)
|
||||
|
||||
def main():
|
||||
Cylinder(10.0, 20.0, 1, 10, 10)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user