""" Kachelung 25 10.09.2015 """ import c4d import math # Variablen und Konstanten N = 5 # Anzahl Punkte pro Kante r = 1 .0 # Kantenlaenge h = 0.5*math.sqrt(3.0) *r # Hoehe Dreieck Abstand_x = 2*r + 2*h Abstand_y = h + r + h + 0.5*r Versatz_x = r + h NS = 5 # Anzahl Wiederholungen in eine Richtung if NS%2 ==0: # nur ungerade NS zulassen NS = NS +1 Faktor = 1000 # Skalierungsfaktor Sexeck = [] Raute1 = [] Viereck = [] Dreieck = [] #Inversion = True Inversion = False def Invers(z): if abs(z) == 0: z = complex(z.real, z.imag + 0.0001) return 1/z def CreateNullobjekt(): obj = c4d.BaseObject(c4d.Onull) # Nullobjekt erzeugen obj.SetName("Kachelung 25") 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) # 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 # Zaehler Punkte # Viereckssdaten erzeugen for i in range(0,N): z = complex(-0.5 * r + i * dt, h) Viereck.append(z) for i in range(0,N): z = complex(0.5*r, h + i * dt) Viereck.append(z) for i in range(0,N): z = complex(0.5*r - i * dt, h + r) Viereck.append(z) for i in range(0,N): z = complex(-0.5 * r, h + r - i * dt) Viereck.append(z) # Viereck duplizieren und drehen for i in range(1,6): for j in range(0,4*N): z = Drehung(Viereck[j], -60*i) 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 # Sechsecke ************************************************************** def CreateSplineObjectS(): # Splineobjekte erzeugen obj = c4d.BaseObject(c4d.Ospline) obj.ResizeObject(N*6*(2*NS+1)*(2*NS+1)) dt= r/N # Unterteilung Kante zz = 0 # Zaehler 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 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): z = Sexeck[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)) for i in range(0, (2*NS+1)*(2*NS+1)): obj.SetSegment(i, 6*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Sechsecke") obj.Message(c4d.MSG_UPDATE) return obj # Rauten *************************************************************************************** def CreateSplineObjectR(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)*3) dt= r/N zz = 0 # Zaehler Punkte # Rautendaten erzeugen for i in range(0,N): z = complex(i * dt, 0) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -60) + complex(r, 0) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -180) + complex(r + 0.5*r, h) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 120) + complex(0.5*r, h) Raute1.append(z) # Raute drehen und verschieben for i in range(0,4*N): Raute1[i] = Drehung(Raute1[i], 30) + complex(r, 0) # Rauten duplizieren und drehen for i in range(0,4*N): z = Drehung(Raute1[i], -60) Raute1.append(z) for i in range(0,4*N): z = Drehung(Raute1[i], 60) Raute1.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*3): z = Raute1[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)*3) for i in range(0, (2*NS+1)*(2*NS+1)*3): obj.SetSegment(i, 4*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Rauten") 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 # Zaehler Punkte # Dreiecksdaten erzeugen for i in range(0,N): z = complex(0.5*r + h + i * dt, -h - 0.5*r) Dreieck.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -120) + complex(1.5*r + h, -h - 0.5*r) Dreieck.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 120) + complex(r + h, -0.5*r) Dreieck.append(z) # Dreieck spiegeln for i in range(0,3*N): z = complex(Dreieck[i].real, -Dreieck[i].imag) 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 = CreateSplineObjectS() slinobj2 = CreateSplineObjectR() slinobj3 = CreateSplineObjectD() slinobj4 = CreateSplineObjectQ() doc.InsertObject(nullobj, None, None, True) doc.InsertObject(slinobj3, nullobj, None, True) doc.InsertObject(slinobj2, nullobj, None, True) doc.InsertObject(slinobj4, nullobj, None, True) doc.InsertObject(slinobj1, nullobj, None, True) c4d.EventAdd() if __name__=='__main__': main()