""" Kachelung 32 12.10.2015 """ import c4d import math # Variablen und Konstanten N = 5 # Anzahl Punkte pro Kante r = 1.0 # Kantenlaenge riz = 0.5*r*(2 + math.sqrt(3.0)) # Inkreisradius Zwoelfeck ht = r*math.cos(math.pi/12) # Hoehe Trapez h1 = 0.5 * math.sqrt(3.0) * (2*riz + 2*ht) # Hoehe grosses Dreieck #a = r*math.cos(2*math.pi/9) #b = r*math.sin(2*math.pi/9) #c = r*math.sin(math.pi/6) #d = r*math.cos(math.pi/6) e = r*math.sin(math.pi/12) f = r + 2*e h = 0.5 * math.sqrt(3.0) * f # Hoehe Dreieck Abstand_x = 2*riz + 2*ht Abstand_y = h1 Versatz_x = riz + ht NS = 5 # Anzahl Wiederholungen in eine Richtung if NS%2 ==0: # nur ungerade NS zulassen NS = NS +1 Faktor = 1000 # Skalierungsfaktor Zwoelfeck = [] Dreieck = [] Trapez1 = [] Trapez2 = [] #Inversion = True Inversion = False def Invers(z): return 1/z def CreateNullobjekt(): obj = c4d.BaseObject(c4d.Onull) # Nullobjekt erzeugen obj.SetName("Kachelung 32") 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) # Trapeze 1 *************************************************************************** def CreateSplineObjectT1(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)*6) dt= r/N dtf= f/N zz = 0 # Zaehler Punkte # Trapezdaten erzeugen for i in range(0,N): z = complex(riz, -0.5 * r + i * dt) Trapez1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -15) + complex(riz, 0.5*r) Trapez1.append(z) for i in range(0,N): z = complex(riz + ht, 0.5 * f - i * dtf) Trapez1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -165) + complex(riz + ht, -0.5*f) Trapez1.append(z) # Trapez duplizieren und drehen for k in range(1,6): for i in range(0,4*N): z = Drehung(Trapez1[i], -60*k) Trapez1.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 = Trapez1[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("Trapeze 1") obj.Message(c4d.MSG_UPDATE) return obj # Trapeze 2 *************************************************************************** def CreateSplineObjectT2(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)*6) dt= r/N dtf= f/N zz = 0 # Zaehler Punkte # Trapezdaten aus Trapez 1 erzeugen for i in range(0,4*N*6): z = Drehung(Trapez1[i], 30) Trapez2.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 = Trapez2[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("Trapeze 2") obj.Message(c4d.MSG_UPDATE) return obj # Zwoelfecke ********************************************************************************** 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 # Zaehler Punkte # Zwoelfeckdaten 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("Zwoelfecke") obj1.Message(c4d.MSG_UPDATE) return obj1 # Dreiecke ****************************************************************************** def CreateSplineObjectD(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*3*(2*NS+1)*(2*NS+1)*2) dtf= f/N zz = 0 # Zaehler Punkte # Dreiecksdaten erzeugen for i in range(0,N): z = complex(riz + ht, -0.5 *f + i * dtf) Dreieck.append(z) for i in range(0,N): z = complex(i * dtf, 0) z = Drehung(z, 30) + complex(riz + ht, 0.5*f) Dreieck.append(z) for i in range(0,N): z = complex(i * dtf, 0) z = Drehung(z, 150) + complex(riz + ht + h, 0) Dreieck.append(z) # Dreieck drehen for i in range(0,3*N): Dreieck[i] = Drehung(Dreieck[i], -30) # 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 = CreateSplineObjectZ() slinobj2 = CreateSplineObjectT1() slinobj3 = CreateSplineObjectT2() slinobj4 = CreateSplineObjectD() doc.InsertObject(nullobj, None, None, True) doc.InsertObject(slinobj4, nullobj, None, True) doc.InsertObject(slinobj3, nullobj, None, True) doc.InsertObject(slinobj2, nullobj, None, True) doc.InsertObject(slinobj1, nullobj, None, True) c4d.EventAdd() if __name__=='__main__': main()