""" Prisma """ import c4d import math N = 8 # Anzahl Ecken Vieleck if N < 3: N=3 R = 1/(2*math.sin(math.pi/N)) # Umkreisradius # w = math.pi/N # Winkel w = 0 NP = N/2-1 # Anzahl Polygone (N gerade) Radius = 2 # Radius der Eckpunktkugeln Faktor = 100 # Punkte erzeugen Punkte = [] for i in xrange(N): Punkte.append(c4d.Vector(Faktor*R*math.cos(w+2*math.pi*i/N), 0.5*Faktor, Faktor*R*math.sin(w+2*math.pi*i/N))) for i in xrange(N): Punkte.append(c4d.Vector(Faktor*R*math.cos(w+2*math.pi*i/N), -0.5*Faktor, Faktor*R*math.sin(w+2*math.pi*i/N))) #************************************************************************ def CreateNullobjekt1(): obj = c4d.BaseObject(c4d.Onull) obj.SetName("Prisma-"+str(N)) obj.Message(c4d.MSG_UPDATE) return obj #************************************************************************ def CreateNullobjekt2(): obj = c4d.BaseObject(c4d.Onull) obj.SetName('Ecken') obj.Message(c4d.MSG_UPDATE) return obj #************************************************************************ def CreateNullobjekt3(): obj = c4d.BaseObject(c4d.Onull) obj.SetName('Kanten') obj.Message(c4d.MSG_UPDATE) return obj #************************************************************************ def CreateNullobjekt4(): obj = c4d.BaseObject(c4d.Onull) obj.SetName('Polygone') obj.Message(c4d.MSG_UPDATE) return obj #------------------------------------------------------------------------------------------------------ # Deckfläche # N ist gerade def CreatePolygonObjectDG(): obj = c4d.BaseObject(c4d.Opolygon) obj.ResizeObject(2*N, 2*NP) obj.SetName('Deckflächen') # Punkte uebergeben for i in xrange(2*N): obj.SetPoint(i,Punkte[i]) # Obere Deckfläche erzeugen zz = 0 obj.SetPolygon(zz, c4d.CPolygon(0, N-1, 2,1)) zz = zz + 1 for i in xrange(1, NP): obj.SetPolygon(zz, c4d.CPolygon(N-i, N-i-1, i+2, i+1)) zz = zz + 1 # Untere Deckfläche erzeugen obj.SetPolygon(zz, c4d.CPolygon(N+2, 2*N-1, N, N+1 )) zz = zz + 1 for i in xrange(1, NP): obj.SetPolygon(zz, c4d.CPolygon(N+i+1, N+i+2, 2*N-i-1, 2*N-i)) zz = zz + 1 obj.Message(c4d.MSG_UPDATE) return obj #------------------------------------------------------------------------------------------------------ # Seitenfläche def CreatePolygonObjectS(): obj = c4d.BaseObject(c4d.Opolygon) obj.ResizeObject(2*N, N) obj.SetName('Seitenflächen') # Punkte uebergeben for i in xrange(2*N): obj.SetPoint(i,Punkte[i]) for i in xrange(0, N-1): obj.SetPolygon(i, c4d.CPolygon(i, i+1, N+i+1, N+i)) obj.SetPolygon(N-1, c4d.CPolygon(N-1, 0, N, 2*N-1)) # letztes Polygon obj.Message(c4d.MSG_UPDATE) return obj #------------------------------------------------------------------------------------------------------ # Deckfläche # N ist ungerade def CreatePolygonObjectDU(): obj = c4d.BaseObject(c4d.Opolygon) obj.ResizeObject(2*N, 2*NP+2) obj.SetName('Deckflächen') # Punkte uebergeben for i in xrange(2*N): obj.SetPoint(i,Punkte[i]) if N == 3: obj.SetPolygon(0, c4d.CPolygon(0, 1, 2, 2)) obj.SetPolygon(1, c4d.CPolygon(5, 4, 3, 3)) else: # Obere Deckfläche erzeugen zz = 0 obj.SetPolygon(zz, c4d.CPolygon(0, N-1, 2,1)) # erstes Viereck zz = zz + 1 for i in xrange(1, NP): obj.SetPolygon(zz, c4d.CPolygon(N-i, N-i-1, i+2, i+1)) zz = zz + 1 obj.SetPolygon(zz, c4d.CPolygon(N-NP, N-NP-1, N-NP-2, N-NP-2)) # letztes Dreieck zz = zz + 1 # Untere Deckfläche erzeugen obj.SetPolygon(zz, c4d.CPolygon(N+2, 2*N-1, N, N+1 )) zz = zz + 1 for i in xrange(1, NP): obj.SetPolygon(zz, c4d.CPolygon(N+i+1, N+i+2, 2*N-i-1, 2*N-i)) zz = zz + 1 obj.SetPolygon(zz, c4d.CPolygon(2*N-NP-2, 2*N-NP-1,2*N-NP,2*N-NP )) # letztes Dreieck zz = zz + 1 obj.Message(c4d.MSG_UPDATE) return obj #************************************************************************ def CreateSplineD(): obj = c4d.BaseObject(c4d.Ospline) obj.SetName("Spline-Deckflächen") obj.ResizeObject(2*N) # zz = 0 for i in xrange(2*N): x = Punkte[i][0] y = Punkte[i][1] z = Punkte[i][2] obj.SetPoint(i, c4d.Vector(x, y, z)) # zz = zz + 1 # Segmente erzeugen obj.MakeVariableTag(c4d.Tsegment, 2) for i in range(0, 2): obj.SetSegment(i, N, True) # Spline schliessen obj[c4d.SPLINEOBJECT_CLOSED] = True# obj.Message(c4d.MSG_UPDATE) return obj #************************************************************************ def CreateSplineS(): obj = c4d.BaseObject(c4d.Ospline) obj.SetName("Spline-Seitenflächen") obj.ResizeObject(2*N) zz = 0 for i in xrange(N): x = Punkte[i][0] y = Punkte[i][1] z = Punkte[i][2] obj.SetPoint(zz, c4d.Vector(x, y, z)) zz = zz + 1 x = Punkte[i+N][0] y = Punkte[i+N][1] z = Punkte[i+N][2] obj.SetPoint(zz, c4d.Vector(x, y, z)) zz = zz + 1 # Segmente erzeugen obj.MakeVariableTag(c4d.Tsegment, N) for i in range(0, N): obj.SetSegment(i, 2, True) # Spline schliessen obj[c4d.SPLINEOBJECT_CLOSED] = True# obj.Message(c4d.MSG_UPDATE) return obj #------------------------------------------------------------------------------------------------------ def main(): nullobj1 = CreateNullobjekt1() nullobj2 = CreateNullobjekt2() # Ecken nullobj3 = CreateNullobjekt3() # Kanten nullobj4 = CreateNullobjekt4() # Polygone doc.InsertObject(nullobj1, None, None, True) doc.InsertObject(nullobj4, nullobj1, None, True) doc.InsertObject(nullobj3, nullobj1, None, True) doc.InsertObject(nullobj2, nullobj1, None, True) if N % 2 == 0: # N ist gerade plyobj1 = CreatePolygonObjectDG() else: # N ist ungerade plyobj1 = CreatePolygonObjectDU() plyobj2 = CreatePolygonObjectS() splobj1 = CreateSplineD() splobj2 = CreateSplineS() doc.InsertObject(plyobj2, nullobj4, None, True) doc.InsertObject(plyobj1, nullobj4, None, True) doc.InsertObject(splobj2, nullobj3, None, True) doc.InsertObject(splobj1, nullobj3, None, True) # Kugeln auf Eckpunkte setzen for i in range(0, 2*N): obj = c4d.BaseObject(c4d.Osphere) obj[c4d.PRIM_SPHERE_RAD] = Radius obj.SetName(str(i)) x = Punkte[i][0] y = Punkte[i][1] z = Punkte[i][2] obj.SetAbsPos(c4d.Vector(x, y, z)) doc.InsertObject(obj, nullobj2, None, True) c4d.EventAdd() if __name__=='__main__': main()