""" Kachelung 20 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 a = r/math.sqrt(2.0) Abstand_x = 2*r Abstand_y = 2*r NS = 7 # Anzahl Wiederholungen in eine Richtung if NS%2 ==0: # nur ungerade NS zulassen NS = NS +1 Faktor = 1000 # Skalierungsfaktor Viereck = [] Sexeck1 = [] Sexeck2 = [] #Inversion = True Inversion = False def Invers(z): return 1/z def CreateNullobjekt(): obj = c4d.BaseObject(c4d.Onull) # Nullobjekt erzeugen obj.SetName("Kachelung 20") 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)) dt= r/N zz = 0 # Zaehler Punkte # Viereckssdaten erzeugen for i in range(0,N): z = complex(-0.5*r + i * dt, -0.5 * r) Viereck.append(z) for i in range(0,N): z = complex(0.5*r, -0.5 * r + i * dt) Viereck.append(z) for i in range(0,N): z = complex(0.5*r - i * dt, 0.5 * r) Viereck.append(z) for i in range(0,N): z = complex(-0.5*r, 0.5 * r - i * dt) 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): x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,4*N): 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)) for i in range(0, (2*NS+1)*(2*NS+1)): obj.SetSegment(i, 4*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Vierecke") obj.Message(c4d.MSG_UPDATE) return obj # Sechsecke 1 ************************************************************** def CreateSplineObjectS1(): # Splineobjekte erzeugen obj = c4d.BaseObject(c4d.Ospline) obj.ResizeObject(N*6*(2*NS+1)*(2*NS+1)) dt = r/N # Unterteilung Kante dta = a/N zz = 0 # Zaehler Punkte # Sechseckdaten erzeugen for i in range(0,N): z = complex(-0.5 * r + i * dt, 0.5 * r) Sexeck1.append(z) for i in range(0,N): z = complex(i * dta, 0) z = Drehung(z, -45) + complex(0.5*r, 0.5*r) Sexeck1.append(z) for i in range(0,N): z = complex(i * dta, 0) z = Drehung(z, -135) + complex(r, r) Sexeck1.append(z) for i in range(0,N): z = complex(0.5 * r - i * dt, 1.5*r) Sexeck1.append(z) for i in range(0,N): z = complex(i * dta, 0) z = Drehung(z, 135) + complex(-0.5*r, 1.5*r) Sexeck1.append(z) for i in range(0,N): z = complex(i * dta, 0) z = Drehung(z, 45) + complex(-r, r) Sexeck1.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): x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,6*N): z = Sexeck1[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 1") obj.Message(c4d.MSG_UPDATE) return obj # Sechsecke 2 ************************************************************** def CreateSplineObjectS2(): # Splineobjekte erzeugen obj = c4d.BaseObject(c4d.Ospline) obj.ResizeObject(N*6*(2*NS+1)*(2*NS+1)) dt = r/N # Unterteilung Kante dta = a/N zz = 0 # Zaehler Punkte # Sechseckdaten erzeugen for i in range(0,6*N): z = Drehung(Sexeck1[i], 90) Sexeck2.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): x0 = -Abstand_x*NS + j*Abstand_x for i in range(0,6*N): z = Sexeck2[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 2") obj.Message(c4d.MSG_UPDATE) return obj def main(): nullobj = CreateNullobjekt() slinobj2 = CreateSplineObjectS1() slinobj3 = CreateSplineObjectS2() slinobj1 = CreateSplineObjectQ() doc.InsertObject(nullobj, None, None, True) doc.InsertObject(slinobj1, nullobj, None, True) doc.InsertObject(slinobj3, nullobj, None, True) doc.InsertObject(slinobj2, nullobj, None, True) c4d.EventAdd() if __name__=='__main__': main()