""" Kachelung 14 10.09.2015 """ import c4d import math # Variablen und Konstanten N = 32 # Anzahl Punkte x r = 1.0 # Kantenlänge h = 0.5 * math.sqrt(3.0) *r # Höhe Dreieck Abstand_x = 2*h Abstand_y = 0.5*r + r Versatz_x = h NS = 5 # Anzahl Wiederholungen in eine Richtung if NS%2 ==0: # nur ungerade NS zulassen NS = NS +1 Faktor = 1000 # Skalierungsfaktor Raute1 = [] Raute2 = [] Raute3 = [] Inversion = True #Inversion = False def Invers(z): z = complex(z.real + 0.01, z.imag + 0.01) return 1/z def CreateNullobjekt(): obj = c4d.BaseObject(c4d.Onull) # Nullobjekt erzeugen obj.SetName("Kachelung 14") 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) # Rauten 1 ****************************************************************************** def CreateSplineObjectR1(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)) dt= r/N zz = 0 # Zähler Punkte # Rautendaten erzeugen for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -120) + complex(0.5*r, ) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 120) + complex(0, h) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 60) + complex(-0.5*r, 0) Raute1.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -60) + complex (0, -h) Raute1.append(z) # Raute positionieren for i in range(0,4*N): Raute1[i] = Drehung(Raute1[i], -30) + complex (-0.5*h, -0.25*r) 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): 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)) for i in range(0, (2*NS+1)*(2*NS+1)): obj.SetSegment(i, 4*N, True) obj[c4d.SPLINEOBJECT_CLOSED] = True obj.SetName("Rauten 1") obj.Message(c4d.MSG_UPDATE) return obj # Rauten 2 ****************************************************************************** def CreateSplineObjectR2(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)) dt= r/N zz = 0 # Zähler Punkte # Rautendaten erzeugen for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -120) + complex(0.5*r, 0) Raute2.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 120) + complex(0, h) Raute2.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 60) + complex(-0.5*r, 0) Raute2.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -60) + complex (0, -h) Raute2.append(z) # Raute positionieren for i in range(0,4*N): Raute2[i] = Drehung(Raute2[i], 30) + complex (0.5*h, -0.25*r) 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): z = Raute2[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("Rauten 2") obj.Message(c4d.MSG_UPDATE) return obj # Rauten 3 ****************************************************************************** def CreateSplineObjectR3(): obj = c4d.BaseObject(c4d.Ospline) # Splineobjekt erzeugen obj.ResizeObject(N*4*(2*NS+1)*(2*NS+1)) dt= r/N zz = 0 # Zähler Punkte # Rautendaten erzeugen for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -120) + complex(0.5*r, ) Raute3.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 120) + complex(0, h) Raute3.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, 60) + complex(-0.5*r, 0) Raute3.append(z) for i in range(0,N): z = complex(i * dt, 0) z = Drehung(z, -60) + complex (0, -h) Raute3.append(z) # Raute positionieren for i in range(0,4*N): Raute3[i] = Drehung(Raute3[i], 90) + complex (0, 0.5*r) 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): z = Raute3[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("Rauten 3") obj.Message(c4d.MSG_UPDATE) return obj def main(): nullobj = CreateNullobjekt() slinobj1 = CreateSplineObjectR3() slinobj2 = CreateSplineObjectR2() slinobj3 = CreateSplineObjectR1() doc.InsertObject(nullobj, None, None, True) doc.InsertObject(slinobj1, nullobj, None, True) doc.InsertObject(slinobj2, nullobj, None, True) doc.InsertObject(slinobj3, nullobj, None, True) c4d.EventAdd() if __name__=='__main__': main()