def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH) glutInitWindowSize(640, 480) glutCreateWindow('GLSrf - Press MB and drag to rotate') glutMotionFunc(on_motion) glutDisplayFunc(on_display) glutReshapeFunc(on_reshape) nurb = gluNewNurbsRenderer() gluNurbsProperty(nurb, GLU_SAMPLING_TOLERANCE, 50.) gluNurbsProperty(nurb, GLU_DISPLAY_MODE, GLU_FILL) glMatrixMode(GL_MODELVIEW) glNewList(1, GL_COMPILE) glMaterialfv(GL_FRONT, GL_SPECULAR, (1.0, 1.0, 1.0, 1.0)) glMaterialfv(GL_FRONT, GL_SHININESS, 100.0) glMaterialfv(GL_FRONT, GL_DIFFUSE, (0.7, 0.0, 0.1, 1.0)) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_DEPTH_TEST) glEnable(GL_AUTO_NORMAL) glEnable(GL_NORMALIZE) pnts = [[0., 3., 4.5, 6.5, 8., 10.], [0., 0., 0., 0., 0., 0.], [2., 2., 7., 4., 6., 4.]] crv1 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 0.5, 2. / 3., 1., 1., 1.]) pnts = [[0., 3., 5., 8., 10.], [10., 10., 10., 10., 10.], [3., 6., 3., 6., 10.]] crv2 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 2. / 3., 1., 1., 1.]) srf = Srf.Ruled(crv1, crv2) gluBeginSurface(nurb) gluNurbsSurface(nurb, srf.uknots, srf.vknots, Numeric.transpose(srf.cntrl, (1, 2, 0)), GL_MAP2_VERTEX_4) gluEndSurface(nurb) glEndList()
def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH) glutInitWindowSize(640, 480) glutCreateWindow('GLSrf - Press MB and drag to rotate') glutMotionFunc(on_motion) glutDisplayFunc(on_display) glutReshapeFunc(on_reshape) nurb = gluNewNurbsRenderer() glMatrixMode(GL_MODELVIEW) glNewList(1, GL_COMPILE) cntrl = [[-5., -7.5, 2.5, 0, -2.5, 7.5, 5.0], [2.5, 5.0, 5.0, .0, -5.0, -5.0, 2.5]] knots = [0., 0., 0., .2, .4, .6, .8, 1., 1., 1.] crv = Crv.Crv(cntrl, knots) glPointSize(10.) glDisable(GL_LIGHTING) glColor3f(1., 1., 1.) glBegin(GL_POINTS) for i in range(crv.cntrl.shape[1]): w = crv.cntrl[-1, i] glVertex3f(crv.cntrl[0, i] / w, crv.cntrl[1, i] / w, crv.cntrl[2, i] / w) glEnd() glBegin(GL_LINE_STRIP) for i in range(crv.cntrl.shape[1]): w = crv.cntrl[-1, i] glVertex3f(crv.cntrl[0, i] / w, crv.cntrl[1, i] / w, crv.cntrl[2, i] / w) glEnd() glColor3f(1., 1., 0.) gluBeginCurve(nurb) gluNurbsCurve(nurb, crv.uknots, numpy.transpose(crv.cntrl), GL_MAP1_VERTEX_4) gluEndCurve(nurb) glEndList()
# Demonstration of a Coons surface from nurbs import Srf, Crv pnts = [[0., 3., 4.5, 6.5, 8., 10.], [0., 0., 0., 0., 0., 0.], [2., 2., 7., 4., 7., 9.]] crv1 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 0.5, 2. / 3., 1., 1., 1.]) pnts = [[0., 3., 5., 8., 10.], [10., 10., 10., 10., 10.], [3., 5., 8., 6., 10.]] crv2 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 2. / 3., 1., 1., 1.]) pnts = [[0., 0., 0., 0.], [0., 3., 8., 10.], [2., 0., 5., 3.]] crv3 = Crv.Crv(pnts, [0., 0., 0., 0.5, 1., 1., 1.]) pnts = [[10., 10., 10., 10., 10.], [0., 3., 5., 8., 10.], [9., 7., 7., 10., 10.]] crv4 = Crv.Crv(pnts, [0., 0., 0., 0.25, 0.75, 1., 1., 1.]) srf = Srf.Coons(crv1, crv2, crv3, crv4) srf.plot()
# Demonstration of a Extrude surface from nurbs import Srf, Crv cntrl = [[-50., -75., 25., 0., -25., 75., 50.], [25., 50., 50., 0., -50., -50., 25.]] knots = [0., 0., 0., .2, .4, .6, .8, 1., 1., 1.] crv = Crv.Crv(cntrl, knots) srf = Srf.Extrude(crv, [0, 0, 5]) srf.plot()
# Demonstration of kntins function from nurbs import Crv cntrl = [[.5, 1.5, 4.5, 3., 7.5, 6., 8.5], [3., 5.5, 5.5, 1.5, 1.5, 4., 4.5]] crv = Crv.Crv(cntrl, [0., 0., 0., 1. / 4., 1. / 2., 3. / 4., 3. / 4., 1., 1., 1.]) crv.plot() crv.kntins([0.125, 0.375, 0.625, 0.875]) crv.plot()
# Demonstration of a Line curve from nurbs import Crv crv = Crv.Line([0, 0], [1, 1]) crv.plot()
# Demonstration of a Circle curve from nurbs import Crv crv = Crv.Circle(5., [1., 2.]) crv.plot()
# Demonstration of a Arc curve import math from nurbs import Crv crv = Crv.Arc(1.,None,0,math.pi/2.) crv.plot()
# Demonstration of a Ruled surface from nurbs import Srf, Crv pnts = [[0., 3., 4.5, 6.5, 8., 10.], [0., 0., 0., 0., 0., 0.], [2., 2., 7., 4., 6., 4.]] crv1 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 0.5, 2. / 3., 1., 1., 1.]) pnts = [[0., 3., 5., 8., 10.], [10., 10., 10., 10., 10.], [3., 6., 3., 6., 10.]] crv2 = Crv.Crv(pnts, [0., 0., 0., 1. / 3., 2. / 3., 1., 1., 1.]) srf = Srf.Ruled(crv1, crv2) srf.plot()
# Demonstration of a unit circle transformed to a inclined ellipse # by first scaling, then rotating and finally translating. import numpy from nurbs import Crv from Nurbs.Util import translate, scale, rotx, roty, deg2rad xx = scale([1., 2.]) xx = numpy.dot(rotx(deg2rad(45)), xx) xx = numpy.dot(roty(deg2rad(12)), xx) xx = numpy.dot(translate([2., 1.]), xx) crv = Crv.UnitCircle() crv.trans(xx) crv.plot()
# Demonstration of a Revolve surface from nurbs import Srf, Crv crv = Crv.Crv([[0, 30, 6, 90], [0, 0, 50, 50]], [0, 0, 0, 0, 1, 1, 1, 1]) srf = Srf.Revolve(crv) srf.plot()
# Demonstration of a Polyline curve from nurbs import Crv crv = Crv.Polyline([[0, 0], [5, 2], [10, 8]]) crv.plot()