⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 triminside.c

📁 Intro/: Directory containing introductory examples. HelloWorld.c A simple program that draws a bo
💻 C
字号:
#include <phigs.h>			/* get HP-PHIGS definitions for C */#include <stdio.h>			/* get standard I/O definitions */#include <math.h>			/* link with library "-lm" */#define deg				*3.1415926535897932384/180main()					/* file "TrimInside.c" */{    Pint		WorkstnID = 1;		/* workstation identifier */    Pint		ConnID;			/* connection identifier */    Pint		WorkstnType = POIDDX;	/* out/in, dir, dbl bfr, X */    Pint		TheMesh = 1;		/* structure ID */    /*--- spline surface data ----------------------------------------------*/    static Pfloat	UknotVals[6] =		/* surface's u knot vector */	{0.0, 0.0, 0.0, 1.0, 1.0, 1.0};    static Pfloat	VknotVals[8] =		/* surface's v knot vector */	{0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};    static Ppoint3	CtrlPts[12] = {		/* surface's control points */	{0.0, 0.0, 0.0}, {0.5, 0.3, 0.0}, {1.0, 0.2, 0.0},	{0.0, 0.1, 0.3}, {0.5, 0.5, 0.3}, {1.0, 0.4, 0.3},	{0.0, 0.3, 0.6}, {0.5, 0.4, 0.6}, {1.0, 0.1, 0.6},	{0.0, 0.0, 0.9}, {0.5, 0.2, 0.9}, {1.0, 0.3, 0.9}};    static Psurf_geom_spline Surface = {	/* spline surface definition */	3, 4,	{6, UknotVals}, {8, VknotVals},	{PB_SPLINE_NON_RATIONAL, 3, 4, CtrlPts}};    /*--- trimming curve data ----------------------------------------------*/    Ptrim_curve_loop_list TrimLoopList;		/* \  data structures for */    Ptrim_curve_loop	TrimLoops[2];		/*  > defining surface's  */    Ptrim_curve		Edge, TrimCurve;	/* /  trimming curves     */    static Ppoint	EdgePts[5] =	{0.0, 0.0,  1.0, 0.0,  1.0, 1.0,  0.0, 1.0,  0.0, 0.0};    static Pfloat	EdgeKnots[7] =	{0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0};    static Ppoint	TrimCurvePts[4] =	{0.35, 0.05,  0.25, 0.95,  0.95, 0.95,  0.35, 0.05};    static Pfloat	TrimCurveKnots[8] =	{0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};    /*--- [trimming] curve- and [spline] surface characteristics -----------*/    Pparam_surf_chars	SurfaceChars;    static Pfloat	Approximations[4] =	/* curve/surface approx */	{0.1, 0.1, 0.1, 0.1};    static Pcurve_approx_crit CurveApproximation =	{PCURVE_APPROX_STEP, 0.1};    Psurf_approx_crit	SurfApproximation;    /*--- miscellaneous data items -----------------------------------------*/    Pint		MeshLabel = 1;		/* structure label */    Pfloat		ThetaMin = 0.0,		/* loop control variables */			ThetaMax = 410.0, dTheta = 1.0, Theta;    Pvec3		Vec;			/* for translation/scaling */    Pmatrix3		xform;			/* transformation matrix */    Pint		Error;			/* error-return variable */    Pint		u, v;			/* loop control variables */    Pint		I, Iu, Iv;		/* temporary array indexes */    popen_phigs((char *) stderr, 0);	/* errors go to "stderr" */    pescape_u4("/dev/screen/phigs_window", &ConnID);    popen_ws(WorkstnID, (void *) ConnID, WorkstnType);    ppost_struct(WorkstnID, TheMesh, 1.0);    /*=== define the spline-generating structure ========================== */    popen_struct(TheMesh);    /*--- set up transformations -------------------------------------------*/    Vec.delta_x = -0.5, Vec.delta_y = 0.0, Vec.delta_z = -0.5;    ptranslate3(&Vec, &Error, xform);    pset_local_tran3(xform, PTYPE_REPLACE);    Vec.delta_x = 0.7, Vec.delta_y = 0.7, Vec.delta_z = 0.7;    pscale3(&Vec, &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    protate_x(30 deg, &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    protate_y(0 deg, &Error, xform);    plabel(MeshLabel);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    Vec.delta_x = 0.5, Vec.delta_y = 0.3, Vec.delta_z = 0.5;    ptranslate3(&Vec, &Error, xform);    pset_local_tran3(xform, PTYPE_POSTCONCAT);    /*--- set delta t (independent variable) -------------------------------*/    SurfApproximation.type = PSURF_APPROX_STEP;    SurfApproximation.data.step_size.sample_size[0] = Approximations[0];    SurfApproximation.data.step_size.sample_size[1] = Approximations[1];    SurfApproximation.data.step_size.sample_size[2] = Approximations[2];    SurfApproximation.data.step_size.sample_size[3] = Approximations[3];    pset_surf_approx_crit(&SurfApproximation);    /*--- define trimming curve for outside edge ---------------------------*/    Edge.approx_crit.type = PCURVE_APPROX_STEP;    Edge.approx_crit.data.step_size.sample_size = 0.1;    Edge.visibility_flag = PVIS_ON;    Edge.order = 2;				/* 2=linear */    Edge.knots.num_floats = 7;    Edge.knots.floats = EdgeKnots;    Edge.low_limit = 0.0;    Edge.high_limit = 4.0;    Edge.ctrl_points.rationality = PB_SPLINE_NON_RATIONAL;    Edge.ctrl_points.num_points = 5;    Edge.ctrl_points.points.point = EdgePts;    /*--- define trimming curve for teardrop-shaped hole -------------------*/    TrimCurve.approx_crit.type = PCURVE_APPROX_STEP;    TrimCurve.approx_crit.data.step_size.sample_size = 0.1;    TrimCurve.visibility_flag = PVIS_ON;    TrimCurve.order = 4;			/* 4=cubic */    TrimCurve.knots.num_floats = 8;    TrimCurve.knots.floats = TrimCurveKnots;    TrimCurve.low_limit = 0.0;    TrimCurve.high_limit = 1.0;    TrimCurve.ctrl_points.rationality = PB_SPLINE_NON_RATIONAL;    TrimCurve.ctrl_points.num_points = 4;    TrimCurve.ctrl_points.points.point = TrimCurvePts;    /*--- install trim curves into trim-loops array ------------------------*/    TrimLoops[0].num_trim_curves = 1;    TrimLoops[0].trim_curves = &Edge;    TrimLoops[1].num_trim_curves = 1;    TrimLoops[1].trim_curves = &TrimCurve;    /*--- install trim loops into trim-loop list ---------------------------*/    TrimLoopList.num_trim_loops = 2;    TrimLoopList.trim_loops = TrimLoops;    /*--- define the b-spline surface --------------------------------------*/    SurfaceChars.type = PPARAM_SURF_CHARS_INT_EDGE;    pset_param_surf_chars(&SurfaceChars);    pnon_uniform_b_spline_surf3(&Surface, &TrimLoopList);    /*---- draw control-point grid ------------------------------------------*/    pset_linetype(PLINE_DOT);			/* set line type */    for (u = 0; u < 4; u++) {	for (v = 0; v < 3; v++) {	    I  = u * 3 + v;			/* index of X(u, v)   */	    Iu = (u + 1) * 3 + v;		/* index of X(u+1, v) */	    Iv = u * 3 + v + 1;			/* index of X(u, v+1) */	    if (u < 3)				/* unless on right edge... */		Line(CtrlPts[I].x, CtrlPts[I].y, CtrlPts[I].z,		  CtrlPts[Iu].x, CtrlPts[Iu].y, CtrlPts[Iu].z);	    if (v < 2)				/* unless on bottom edge... */		Line(CtrlPts[I].x, CtrlPts[I].y, CtrlPts[I].z,		  CtrlPts[Iv].x, CtrlPts[Iv].y, CtrlPts[Iv].z);	}    }    pclose_struct();    /*=== rotate the spline surface ======================================= */    for (Theta = ThetaMin; Theta < ThetaMax; Theta += dTheta) {	popen_struct(TheMesh);	protate_y(Theta deg, &Error, xform);	pset_elem_ptr(1);	pset_elem_ptr_label(MeshLabel);	poffset_elem_ptr(1);	pset_edit_mode(PEDIT_REPLACE);	pset_local_tran3(xform, PTYPE_POSTCONCAT);	pclose_struct();	pupd_ws(WorkstnID, PFLAG_PERFORM);    }    pclose_ws(WorkstnID);    pclose_phigs();}/****************************************************************************/Line(X1, Y1, Z1, X2, Y2, Z2)float	X1, Y1, Z1, X2, Y2, Z2;		/* "from" point, "to" point */{    Ppoint3		Pts[2];		/* for 3D polyline */    Ppoint_list3	Line;        Pts[0].x = X1;			/* \				*/    Pts[0].y = Y1;			/*  \				*/    Pts[0].z = Z1;			/*   \ put the individual	*/    Pts[1].x = X2;			/*   / values into the arrays	*/    Pts[1].y = Y2;			/*  /				*/    Pts[1].z = Z2;			/* /				*/    Line.num_points = 2;    Line.points = Pts;    ppolyline3(&Line);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -