""" Kachelung 19 10.09.2015 """ import c4d import math # Variablen und Konstanten N = 32 # Anzahl Punkte pro Kante r = 1.0 # Kantenlänge Zwölfeck und Quadrat riz = 0.5*r*(2 + math.sqrt(3.0)) # Inkreisradius Zwölfeck h = 0.5 * math.sqrt(3.0) *r # Höhe Dreieck Abstand_x = 2*riz + 2*h + 4*r Abstand_y = riz + h Versatz_x = riz + 2*r + h NS = 9 # Anzahl Wiederholungen in eine Richtung if NS%2 ==0: # nur ungerade NS zulassen NS = NS +1 Faktor = 1000 # Skalierungsfaktor Zwoelfeck = [] Viereck = [] Sexeck = [] Dreieck = [] Inversion = True #Inversion = False def Invers(z): return 1/z def CreateNullobjekt(): obj = c4d.BaseObject(c4d.Onull) # Nullobjekt erzeugen obj.SetName("Kachelung 19") obj.Message(c4d.MSG_UPDATE) return obj def Drehung(z, Grad): Winkel = Grad * math.pi/180 x = z.real y = z.imag x1 = math.cos(Winkel) * x + math.sin(Winkel) * y y1 = -math.sin(Winkel) * x + math.cos(Winkel) * y return complex(x1, y1) # Sechsecke **************************************************************************** def CreateSplineObjectS(): # Splineobjekte erzeugen obj2 = c4d.BaseObject(c4d.Ospline) obj2.ResizeObject(N*6*(2*NS+1)*(2*NS+1)*3) dt= r/N # Unterteilung Kante zz = 0 # Zähler Punkte # Sechseckdaten erzeugen for i in range(0,N): z = complex(-0.5 * r + i * dt, -h) Sexeck.append(z) for k in range(1,6): for j in range(0,N): z = Drehung(Sexeck[j], -60*k) Sexeck.append(z) for j in range(0,6*N): Sexeck[j] = Sexeck[j] + complex(0, riz + h) for j in range(0,6*N): z = Drehung(Sexeck[j], 60) Sexeck.append(z) for j in range(0,6*N): z = Drehung(Sexeck[j], 120) Sexeck.append(z) for k in range(0,2*NS+1): y0 = -Abstand_y*NS + k*Abstand_y for j in range(0,2*NS+1): if k%2 == 0.0: x0 = -Abstand_x*NS + j*Abstand_x + Versatz_x else: x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,6*N*3): z = Sexeck[i] + complex(x0, y0) if Inversion: z = Invers(z) obj2.SetPoint(zz, c4d.Vector(z.real*Faktor, z.imag*Faktor, 0.0)) zz = zz + 1 obj2.MakeVariableTag(c4d.Tsegment, (2*NS+1)*(2*NS+1)*3) for i in range(0, (2*NS+1)*(2*NS+1)*3): obj2.SetSegment(i, 6*N, True) obj2[c4d.SPLINEOBJECT_CLOSED] = True obj2.SetName("Sechsecke") obj2.Message(c4d.MSG_UPDATE) return obj2 # Zwölfecke **************************************************************************** def CreateSplineObjectZ(): # Splineobjekte erzeugen obj1 = c4d.BaseObject(c4d.Ospline) obj1.ResizeObject(N*12*(2*NS+1)*(2*NS+1)) dt= r/N # Unterteilung Kante zz = 0 # Zähler Punkte # Zwölfeckdaten erzeugen for i in range(0,N): z = complex(-0.5 * r + i * dt, -riz) Zwoelfeck.append(z) for k in range(1,12): for j in range(0,N): z = Drehung(Zwoelfeck[j], -30*k) Zwoelfeck.append(z) for k in range(0,2*NS+1): y0 = -Abstand_y*NS + k*Abstand_y for j in range(0,2*NS+1): if k%2 == 0.0: x0 = -Abstand_x*NS + j*Abstand_x + Versatz_x else: x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,12*N): z = Zwoelfeck[i] + complex(x0, y0) if Inversion: z = Invers(z) obj1.SetPoint(zz, c4d.Vector(z.real*Faktor, z.imag*Faktor, 0.0)) zz = zz + 1 obj1.MakeVariableTag(c4d.Tsegment, (2*NS+1)*(2*NS+1)) for i in range(0, (2*NS+1)*(2*NS+1)): obj1.SetSegment(i, 12*N, True) obj1[c4d.SPLINEOBJECT_CLOSED] = True obj1.SetName("Zwölfecke") obj1.Message(c4d.MSG_UPDATE) return obj1 # Vierecke *************************************************************************** def CreateSplineObjectQ(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)*6) dt= r/N zz = 0 # Zähler Punkte # Viereckssdaten erzeugen for i in range(0,N): z = complex(riz + i * dt, -0.5 * r) Viereck.append(z) for i in range(0,N): z = complex(riz + r, -0.5 * r + i * dt) Viereck.append(z) for i in range(0,N): z = complex(riz + r - i * dt, 0.5 * r) Viereck.append(z) for i in range(0,N): z = complex(riz, 0.5 * r - i * dt) Viereck.append(z) # Viereck duplizieren und drehen for k in range(1,6): for i in range(0,4*N): z = Drehung(Viereck[i], -60*k) Viereck.append(z) for k in range(0,2*NS+1): y0 = -Abstand_y*NS + k*Abstand_y for j in range(0,2*NS+1): if k%2 == 0.0: x0 = -Abstand_x*NS + j*Abstand_x + Versatz_x else: x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,4*N*6): z = Viereck[i] + complex(x0, y0) if Inversion: z = Invers(z) obj.SetPoint(zz, c4d.Vector(z.real*Faktor, z.imag*Faktor, 0.0)) zz = zz + 1 obj.MakeVariableTag(c4d.Tsegment, (2*NS+1)*(2*NS+1)*6) for i in range(0, (2*NS+1)*(2*NS+1)*6): obj.SetSegment(i, 4*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Vierecke") obj.Message(c4d.MSG_UPDATE) return obj # Dreiecke ************************************************************************** def CreateSplineObjectD(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*3*(2*NS+1)*(2*NS+1)*2) dt= r/N zz = 0 # Zähler Punkte # Dreiecksdaten erzeugen for i in range(0,N): z = complex(riz + r, 0.5 * r - i * dt) Dreieck.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -30) + complex(riz + r, -0.5*r) Dreieck.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -150) + complex(2*h + 2*r, 0) Dreieck.append(z) for i in range(0,3*N): z = Drehung(Dreieck[i], -60) Dreieck.append(z) for k in range(0,2*NS+1): y0 = -Abstand_y*NS + k*Abstand_y for j in range(0,2*NS+1): if k%2 == 0.0: x0 = -Abstand_x*NS + j*Abstand_x + Versatz_x else: x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,3*N*2): z = Dreieck[i] + complex(x0, y0) if Inversion: z = Invers(z) obj.SetPoint(zz, c4d.Vector(z.real*Faktor, z.imag*Faktor, 0.0)) zz = zz + 1 obj.MakeVariableTag(c4d.Tsegment, (2*NS+1)*(2*NS+1)*2) for i in range(0, (2*NS+1)*(2*NS+1)*2): obj.SetSegment(i, 3*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Dreiecke") obj.Message(c4d.MSG_UPDATE) return obj def main(): nullobj = CreateNullobjekt() slinobj1 = CreateSplineObjectZ() slinobj2 = CreateSplineObjectQ() slinobj3 = CreateSplineObjectS() slinobj4 = CreateSplineObjectD() doc.InsertObject(nullobj, None, None, True) doc.InsertObject(slinobj1, nullobj, None, True) doc.InsertObject(slinobj2, nullobj, None, True) doc.InsertObject(slinobj3, nullobj, None, True) doc.InsertObject(slinobj4, nullobj, None, True) c4d.EventAdd() if __name__=='__main__': main()