""" Virich Cyclic Surface 16.04.2020 """ import c4d import math # Variablen und Konstanten dialog_title = 'Virich Cyclic Surface' a = 1.5 # Konstante a b = 3.0 # Konstante b c = 2.0 # Konstante c d = 4.0 # Konstante d uMin = 0.0 # Bereich u uMax = 2*math.pi # Bereich u vMin = 0.0 # Bereich v vMax = 2*math.pi # Bereich v Nu = 30 # Anzahl Punkte u Nv = 60 # Anzahl Punkte v Faktor = 100 # Skalierungsfaktor def CreatePolygonObject(): # Polygonobjekt erzeugen obj = c4d.BaseObject(c4d.Opolygon) obj.ResizeObject((Nu+1)*(Nv+1), Nu*Nv) obj.SetName(dialog_title) # Variablen zz=0 # Zaehler # Segmentbreiten berechnen du=(uMax-uMin)/Nu dv=(vMax-vMin)/Nv # Punkte erzeugen for i in xrange(0,Nu+1): for j in xrange(0,Nv+1): # Berechnung der Parameter u=uMin+i*du v=vMin+j*dv # Berechnung der Koordinaten f= (a*b)/(math.sqrt(a*a*math.sin(v)*math.sin(v)+b*b*math.cos(v)*math.cos(v))) h1= 1 + math.cos(u) h2=(d*d - c*c)*((1-math.cos(u))/f) x= 0.5*(f*h1 + h2)*math.cos(v) y= 0.5*(f*h1 + h2)*math.sin(v) z= 0.5*(f-(d*d-c*c)/f)*math.sin(u) # Punkt speichern obj.SetPoint(zz, c4d.Vector(x*Faktor,y*Faktor,z*Faktor)) # Zähler erhöhen zz=zz+1 # Polygone erzeugen zz=0 # Zähler zurücksetzen for j in xrange(0,Nv): for i in xrange(0,Nu): # Punkte für ein Quadrat definieren P1=i*(Nv+1)+j P2=i*(Nv+1)+j+1 P3=(i+1)*(Nv+1)+j+1 P4=(i+1)*(Nv+1)+j # Quadrat speichern obj.SetPolygon(zz, c4d.CPolygon(P1,P2,P3,P4)) # Zähler erhöhen zz=zz+1 # obj.Message(c4d.MSG_UPDATE) return obj def main(): plyobj = CreatePolygonObject() doc.InsertObject(plyobj, None, None, True) c4d.EventAdd() if __name__=='__main__': main()