home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-26 | 48.3 KB | 1,555 lines |
- Newsgroups: comp.sources.misc
- From: gershon%gr@cs.utah.edu (Elber Gershon)
- Subject: v24i027: gnuplot3 - interactive function plotting utility, Part05/26
- Message-ID: <1991Oct26.222257.6369@sparky.imd.sterling.com>
- X-Md4-Signature: afb83635085983cbd4979dcbadb73bd6
- Date: Sat, 26 Oct 1991 22:22:57 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: gershon%gr@cs.utah.edu (Elber Gershon)
- Posting-number: Volume 24, Issue 27
- Archive-name: gnuplot3/part05
- Environment: UNIX, MS-DOS, VMS
- Supersedes: gnuplot2: Volume 11, Issue 65-79
-
- #!/bin/sh
- # this is Part.05 (part 5 of a multipart archive)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file gnuplot/contour.c continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 5; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping gnuplot/contour.c'
- else
- echo 'x - continuing file gnuplot/contour.c'
- sed 's/^X//' << 'SHAR_EOF' >> 'gnuplot/contour.c' &&
- X "contour cntr_struct");
- X p_cntr -> X = p_edge -> vertex[1] -> X * t +
- X p_edge -> vertex[0] -> X * (1-t);
- X p_cntr -> Y = p_edge -> vertex[1] -> Y * t +
- X p_edge -> vertex[0] -> Y * (1-t);
- X return p_cntr;
- X }
- }
- X
- /*
- X * Simple routine to decide if two real values are equal by simply
- X * calculating the relative/absolute error between them (< EPSILON).
- X */
- static int fuzzy_equal(x, y)
- double x, y;
- {
- X if (abs(x) > EPSILON) /* Calculate relative error: */
- X return (abs((x - y) / x) < EPSILON);
- X else /* Calculate absolute error: */
- X return (abs(x - y) < EPSILON);
- }
- X
- /*
- X * Generate the triangles.
- X * Returns the lists (vrtxs edges & polys) via pointers to their heads.
- X */
- static void gen_triangle(num_isolines, iso_lines, p_polys, p_edges,
- X p_vrts, x_min, y_min, z_min, x_max, y_max, z_max)
- int num_isolines;
- struct iso_curve *iso_lines;
- struct poly_struct **p_polys;
- struct edge_struct **p_edges;
- struct vrtx_struct **p_vrts;
- double *x_min, *y_min, *z_min, *x_max, *y_max, *z_max;
- {
- X int i, grid_x_max = iso_lines->p_count;
- X struct vrtx_struct *p_vrtx1, *p_vrtx2, *pv_temp;
- X struct edge_struct *p_edge1, *p_edge2, *pe_tail1, *pe_tail2, *pe_temp,
- X *p_edge_middle, *pe_m_tail;
- X struct poly_struct *p_poly, *pp_tail;
- X
- X *p_polys = NULL;
- X *p_edges = NULL;
- X *p_vrts = NULL;
- X *z_min = INFINITY;
- X *y_min = INFINITY;
- X *x_min = INFINITY;
- X *z_max = -INFINITY;
- X *y_max = -INFINITY;
- X *x_max = -INFINITY;
- X
- X /* Read 1st row. */
- X p_vrtx1 = gen_vertices(grid_x_max, iso_lines->points,
- X x_min, y_min, z_min, x_max, y_max, z_max);
- X *p_vrts = p_vrtx1;
- X /* Gen. its edges.*/
- X pe_temp = p_edge1 = gen_edges(grid_x_max, p_vrtx1, &pe_tail1);
- X for (i = 1; i < grid_x_max; i++) {/* Mark one side of edges as boundary. */
- X pe_temp -> poly[1] = NULL;
- X pe_temp = pe_temp -> next;
- X }
- X for (i = 1; i < num_isolines; i++) { /* Read next column and gen. polys. */
- X iso_lines = iso_lines->next;
- X /* Get row into list. */
- X p_vrtx2 = gen_vertices(grid_x_max, iso_lines->points,
- X x_min, y_min, z_min, x_max, y_max, z_max);
- X /* Generate its edges. */
- X p_edge2 = gen_edges(grid_x_max, p_vrtx2, &pe_tail2);
- X /* Generate edges from one vertex list to the other one: */
- X p_edge_middle = gen_edges_middle(grid_x_max, p_vrtx1, p_vrtx2,
- X &pe_m_tail);
- X
- X /* Now we can generate the polygons themselves (triangles). */
- X p_poly = gen_polys(grid_x_max, p_edge1, p_edge_middle, p_edge2,
- X &pp_tail);
- X pe_tail1 -> next = (*p_edges); /* Chain new edges to main list. */
- X pe_m_tail -> next = p_edge1;
- X *p_edges = p_edge_middle;
- X pe_tail1 = pe_tail2;
- X p_edge1 = p_edge2;
- X
- X pv_temp = p_vrtx2;
- X while (pv_temp -> next) pv_temp = pv_temp -> next;
- X pv_temp -> next = *p_vrts;
- X *p_vrts = p_vrtx1 = p_vrtx2;
- X
- X pp_tail -> next = (*p_polys); /* Chain new polys to main list. */
- X *p_polys = p_poly;
- X }
- X
- X pe_temp = p_edge1;
- X for (i = 1; i < grid_x_max; i++) {/* Mark one side of edges as boundary. */
- X pe_temp -> poly[0] = NULL;
- X pe_temp = pe_temp -> next;
- X }
- X
- X pe_tail1 -> next = (*p_edges); /* Chain last edges list to main list. */
- X *p_edges = p_edge1;
- X
- X /* Update the boundary flag, saved in each edge, and update indexes: */
- X pe_temp = (*p_edges);
- X i = 1;
- X
- X while (pe_temp) {
- X pe_temp -> boundary = (!(pe_temp -> poly[0])) ||
- X (!(pe_temp -> poly[1]));
- X pe_temp = pe_temp -> next;
- X }
- }
- X
- /*
- X * Handles grid_x_max 3D points (One row) and generate linked list for them.
- X */
- static struct vrtx_struct *gen_vertices(grid_x_max, points,
- X x_min, y_min, z_min, x_max, y_max, z_max)
- int grid_x_max;
- struct coordinate *points;
- double *x_min, *y_min, *z_min, *x_max, *y_max, *z_max;
- {
- X int i;
- X struct vrtx_struct *p_vrtx, *pv_tail, *pv_temp;
- X
- X for (i=0; i<grid_x_max; i++) {/* Get a point and generate the structure. */
- X pv_temp = (struct vrtx_struct *) alloc(sizeof(struct vrtx_struct),
- X "contour vertex");
- X pv_temp -> X = points[i].x;
- X pv_temp -> Y = points[i].y;
- X pv_temp -> Z = points[i].z;
- X
- X if (pv_temp -> X > *x_max) *x_max = pv_temp -> X; /* Update min/max. */
- X if (pv_temp -> Y > *y_max) *y_max = pv_temp -> Y;
- X if (pv_temp -> Z > *z_max) *z_max = pv_temp -> Z;
- X if (pv_temp -> X < *x_min) *x_min = pv_temp -> X;
- X if (pv_temp -> Y < *y_min) *y_min = pv_temp -> Y;
- X if (pv_temp -> Z < *z_min) *z_min = pv_temp -> Z;
- X
- X if (i == 0) /* First vertex in row: */
- X p_vrtx = pv_tail = pv_temp;
- X else {
- X pv_tail -> next = pv_temp; /* Stick new record as last one. */
- X pv_tail = pv_tail -> next; /* And continue to last record. */
- X }
- X }
- X pv_tail -> next = NULL;
- X
- X return p_vrtx;
- }
- X
- /*
- X * Combines N vertices in pair to form N-1 edges.
- X * Returns pointer to the edge list (pe_tail will point on last edge in list).
- X */
- static struct edge_struct *gen_edges(grid_x_max, p_vrtx, pe_tail)
- int grid_x_max;
- struct vrtx_struct *p_vrtx;
- struct edge_struct **pe_tail;
- {
- X int i;
- X struct edge_struct *p_edge, *pe_temp;
- X
- X for (i=0; i<grid_x_max-1; i++) { /* Generate grid_x_max-1 edges: */
- X pe_temp = (struct edge_struct *) alloc(sizeof(struct edge_struct),
- X "contour edge");
- X pe_temp -> vertex[0] = p_vrtx; /* First vertex of edge. */
- X p_vrtx = p_vrtx -> next; /* Skip to next vertex. */
- X pe_temp -> vertex[1] = p_vrtx; /* Second vertex of edge. */
- X if (i == 0) /* First edge in row: */
- X p_edge = (*pe_tail) = pe_temp;
- X else {
- X (*pe_tail) -> next = pe_temp; /* Stick new record as last one. */
- X *pe_tail = (*pe_tail) -> next; /* And continue to last record. */
- X }
- X }
- X (*pe_tail) -> next = NULL;
- X
- X return p_edge;
- }
- X
- /*
- X * Combines 2 lists of N vertices each into edge list:
- X * The dots (.) are the vertices list, and the . . . .
- X * edges generated are alternations of vertical edges |\ |\ |\ |
- X * (|) and diagonal ones (\). | \| \| \|
- X * A pointer to edge list (alternate | , \) is returned . . . .
- X * Note this list will have (2*grid_x_max-1) edges (pe_tail points on last
- X * record).
- X */
- static struct edge_struct *gen_edges_middle(grid_x_max, p_vrtx1, p_vrtx2,
- X pe_tail)
- int grid_x_max;
- struct vrtx_struct *p_vrtx1, *p_vrtx2;
- struct edge_struct **pe_tail;
- {
- X int i;
- X struct edge_struct *p_edge, *pe_temp;
- X
- X /* Gen first (|). */
- X pe_temp = (struct edge_struct *) alloc(sizeof(struct edge_struct),
- X "contour edge");
- X pe_temp -> vertex[0] = p_vrtx2; /* First vertex of edge. */
- X pe_temp -> vertex[1] = p_vrtx1; /* Second vertex of edge. */
- X p_edge = (*pe_tail) = pe_temp;
- X
- X /* Advance in vrtx list grid_x_max-1 times, and gen. 2 edges /| for each.*/
- X for (i=0; i<grid_x_max-1; i++) {
- X /* The / edge. */
- X pe_temp = (struct edge_struct *) alloc(sizeof(struct edge_struct),
- X "contour edge");
- X pe_temp -> vertex[0] = p_vrtx1; /* First vertex of edge. */
- X pe_temp -> vertex[1] = p_vrtx2 -> next; /* Second vertex of edge. */
- X (*pe_tail) -> next = pe_temp; /* Stick new record as last one. */
- X *pe_tail = (*pe_tail) -> next; /* And continue to last record. */
- X
- X /* The | edge. */
- X pe_temp = (struct edge_struct *) alloc(sizeof(struct edge_struct),
- X "contour edge");
- X pe_temp -> vertex[0] = p_vrtx2 -> next; /* First vertex of edge. */
- X pe_temp -> vertex[1] = p_vrtx1 -> next; /* Second vertex of edge. */
- X (*pe_tail) -> next = pe_temp; /* Stick new record as last one. */
- X *pe_tail = (*pe_tail) -> next; /* And continue to last record. */
- X
- X p_vrtx1 = p_vrtx1 -> next; /* Skip to next vertices in both lists. */
- X p_vrtx2 = p_vrtx2 -> next;
- X }
- X (*pe_tail) -> next = NULL;
- X
- X return p_edge;
- }
- X
- /*
- X * Combines 3 lists of edges into triangles:
- X * 1. p_edge1: Top horizontal edge list: -----------------------
- X * 2. p_edge_middge: middle edge list: |\ |\ |\ |\ |\ |\ |
- X * | \| \| \| \| \| \|
- X * 3. p_edge2: Bottom horizontal edge list: -----------------------
- X * Note that p_edge1/2 lists has grid_x_max-1 edges, while p_edge_middle has
- X * (2*grid_x_max-1) edges.
- X * The routine simple scans the two list Upper 1 Lower
- X * and generate two triangle upper one ---- | \
- X * and lower one from the lists: 0\ |2 0| \1
- X * (Nums. are edges order in polys) \ | ----
- X * The routine returns a pointer to a 2
- X * polygon list (pp_tail points on last polygon). 1
- X * -----------
- X * In addition, the edge lists are updated - | \ 0 |
- X * each edge has two pointers on the two | \ |
- X * (one active if boundary) polygons which 0|1 0\1 0|1
- X * uses it. These two pointer to polygons | \ |
- X * are named: poly[0], poly[1]. The diagram | 1 \ |
- X * on the right show how they are used for the -----------
- X * upper and lower polygons. 0
- X */
- static struct poly_struct *gen_polys(grid_x_max, p_edge1, p_edge_middle,
- X p_edge2, pp_tail)
- int grid_x_max;
- struct edge_struct *p_edge1, *p_edge_middle, *p_edge2;
- struct poly_struct **pp_tail;
- {
- X int i;
- X struct poly_struct *p_poly, *pp_temp;
- X
- X p_edge_middle -> poly[0] = NULL; /* Its boundary! */
- X
- X /* Advance in vrtx list grid_x_max-1 times, and gen. 2 polys for each. */
- X for (i=0; i<grid_x_max-1; i++) {
- X /* The Upper. */
- X pp_temp = (struct poly_struct *) alloc(sizeof(struct poly_struct),
- X "contour poly");
- X /* Now update polys about its edges, and edges about the polygon. */
- X pp_temp -> edge[0] = p_edge_middle -> next;
- X p_edge_middle -> next -> poly[1] = pp_temp;
- X pp_temp -> edge[1] = p_edge1;
- X p_edge1 -> poly[0] = pp_temp;
- X pp_temp -> edge[2] = p_edge_middle -> next -> next;
- X p_edge_middle -> next -> next -> poly[0] = pp_temp;
- X if (i == 0) /* Its first one in list: */
- X p_poly = (*pp_tail) = pp_temp;
- X else {
- X (*pp_tail) -> next = pp_temp;
- X *pp_tail = (*pp_tail) -> next;
- X }
- X
- X /* The Lower. */
- X pp_temp = (struct poly_struct *) alloc(sizeof(struct poly_struct),
- X "contour poly");
- X /* Now update polys about its edges, and edges about the polygon. */
- X pp_temp -> edge[0] = p_edge_middle;
- X p_edge_middle -> poly[1] = pp_temp;
- X pp_temp -> edge[1] = p_edge_middle -> next;
- X p_edge_middle -> next -> poly[0] = pp_temp;
- X pp_temp -> edge[2] = p_edge2;
- X p_edge2 -> poly[1] = pp_temp;
- X (*pp_tail) -> next = pp_temp;
- X *pp_tail = (*pp_tail) -> next;
- X
- X p_edge1 = p_edge1 -> next;
- X p_edge2 = p_edge2 -> next;
- X p_edge_middle = p_edge_middle -> next -> next;
- X }
- X p_edge_middle -> poly[1] = NULL; /* Its boundary! */
- X (*pp_tail) -> next = NULL;
- X
- X return p_poly;
- }
- X
- /*
- X * Calls the (hopefully) desired interpolation/approximation routine.
- X */
- static void put_contour(p_cntr, z_level, x_min, x_max, y_min, y_max, contr_kind)
- struct cntr_struct *p_cntr;
- double z_level, x_min, x_max, y_min, y_max;
- int contr_kind;
- {
- X if (!p_cntr) return; /* Nothing to do if it is empty contour. */
- X
- X switch (interp_kind) {
- X case INTERP_NOTHING: /* No interpolation/approximation. */
- X put_contour_nothing(p_cntr);
- X break;
- X case INTERP_CUBIC: /* Cubic spline interpolation. */
- X put_contour_cubic(p_cntr, z_level, x_min, x_max, y_min, y_max,
- X contr_kind);
- X break;
- X case APPROX_BSPLINE: /* Bspline approximation. */
- X put_contour_bspline(p_cntr, z_level, x_min, x_max, y_min, y_max,
- X contr_kind);
- X break;
- X }
- X
- X free_contour(p_cntr);
- }
- X
- /*
- X * Simply puts contour coordinates in order with no interpolation or
- X * approximation.
- X */
- static put_contour_nothing(p_cntr)
- struct cntr_struct *p_cntr;
- {
- X while (p_cntr) {
- X add_cntr_point(p_cntr -> X, p_cntr -> Y);
- X p_cntr = p_cntr -> next;
- X }
- X end_crnt_cntr();
- }
- X
- /*
- X * Find Complete Cubic Spline Interpolation.
- X */
- static put_contour_cubic(p_cntr, z_level, x_min, x_max, y_min, y_max,
- X contr_kind)
- struct cntr_struct *p_cntr;
- double z_level, x_min, x_max, y_min, y_max;
- int contr_kind;
- {
- X int num_pts, i;
- X double tx1, ty1, tx2, ty2; /* Tangents at end points. */
- X struct cntr_struct *pc_temp;
- X
- X num_pts = count_contour(p_cntr); /* Number of points in contour. */
- X
- X if (num_pts > 2) { /* Take into account 3 points in tangent estimation. */
- X calc_tangent(3, p_cntr -> X, p_cntr -> next -> X,
- X p_cntr -> next -> next -> X,
- X p_cntr -> Y, p_cntr -> next -> Y,
- X p_cntr -> next -> next -> Y, &tx1, &ty1);
- X pc_temp = p_cntr;
- X for (i=3; i<num_pts; i++) pc_temp = pc_temp -> next;/* Go to the end.*/
- X calc_tangent(3, pc_temp -> next -> next -> X,
- X pc_temp -> next -> X, pc_temp -> X,
- X pc_temp -> next -> next -> Y,
- X pc_temp -> next -> Y, pc_temp -> Y, &tx2, &ty2);
- X tx2 = (-tx2); /* Inverse the vector as we need opposite direction. */
- X ty2 = (-ty2);
- X }
- X /* If following (num_pts > 1) is TRUE then exactly 2 points in contour. */
- X else if (num_pts > 1) {/* Take into account 2 points in tangent estimat. */
- X calc_tangent(2, p_cntr -> X, p_cntr -> next -> X, 0.0,
- X p_cntr -> Y, p_cntr -> next -> Y, 0.0, &tx1, &ty1);
- X calc_tangent(2, p_cntr -> next -> X, p_cntr -> X, 0.0,
- X p_cntr -> next -> Y, p_cntr -> Y, 0.0, &tx2, &ty2);
- X tx2 = (-tx2); /* Inverse the vector as we need opposite direction. */
- X ty2 = (-ty2);
- X }
- X else return; /* Only one point (???) - ignore it. */
- X
- X switch (contr_kind) {
- X case OPEN_CONTOUR:
- X break;
- X case CLOSED_CONTOUR:
- X tx1 = tx2 = (tx1 + tx2) / 2.0; /* Make tangents equal. */
- X ty1 = ty2 = (ty1 + ty2) / 2.0;
- X break;
- X }
- X complete_spline_interp(p_cntr, num_pts, 0.0, 1.0, tx1, ty1, tx2, ty2);
- X end_crnt_cntr();
- }
- X
- /*
- X * Find Bspline approximation for this data set.
- X * Uses global variable num_approx_pts to determine number of samples per
- X * interval, where the knot vector intervals are assumed to be uniform, and
- X * Global variable bspline_order for the order of Bspline to use.
- X */
- static put_contour_bspline(p_cntr, z_level, x_min, x_max, y_min, y_max,
- X contr_kind)
- struct cntr_struct *p_cntr;
- double z_level, x_min, x_max, y_min, y_max;
- int contr_kind;
- {
- X int num_pts, i, order = bspline_order;
- X struct cntr_struct *pc_temp;
- X
- X num_pts = count_contour(p_cntr); /* Number of points in contour. */
- X if (num_pts < 2) return; /* Cannt do nothing if empty or one points! */
- X /* Order must be less than number of points in curve - fix it if needed. */
- X if (order > num_pts - 1) order = num_pts - 1;
- X
- X gen_bspline_approx(p_cntr, num_pts, order, contr_kind);
- X end_crnt_cntr();
- }
- X
- /*
- X * Estimate the tangents according to the n last points where n might be
- X * 2 or 3 (if 2 onlt x1, x2).
- X */
- static calc_tangent(n, x1, x2, x3, y1, y2, y3, tx, ty)
- int n;
- double x1, x2, x3, y1, y2, y3, *tx, *ty;
- {
- X double v1[2], v2[2], v1_magnitude, v2_magnitude;
- X
- X switch (n) {
- X case 2:
- X *tx = (x2 - x1) * 0.3;
- X *ty = (y2 - y1) * 0.3;
- X break;
- X case 3:
- X v1[0] = x2 - x1; v1[1] = y2 - y1;
- X v2[0] = x3 - x2; v2[1] = y3 - y2;
- X v1_magnitude = sqrt(sqr(v1[0]) + sqr(v1[1]));
- X v2_magnitude = sqrt(sqr(v2[0]) + sqr(v2[1]));
- X *tx = (v1[0] / v1_magnitude) - (v2[0] / v2_magnitude) * 0.1;
- X *tx *= v1_magnitude * 0.1; /* Make tangent less than magnitude. */
- X *ty = (v1[1] / v1_magnitude) - (v2[1] / v2_magnitude) * 0.1;
- X *ty *= v1_magnitude * 0.1; /* Make tangent less than magnitude. */
- X break;
- X default: /* Should not happen! */
- X (*ty) = 0.1;
- X *tx = 0.1;
- X break;
- X }
- }
- X
- /*
- X * Free all elements in the contour list.
- X */
- static void free_contour(p_cntr)
- struct cntr_struct *p_cntr;
- {
- X struct cntr_struct *pc_temp;
- X
- X while (p_cntr) {
- X pc_temp = p_cntr;
- X p_cntr = p_cntr -> next;
- X free((char *) pc_temp);
- X }
- }
- X
- /*
- X * Counts number of points in contour.
- X */
- static int count_contour(p_cntr)
- struct cntr_struct *p_cntr;
- {
- X int count = 0;
- X
- X while (p_cntr) {
- X count++;
- X p_cntr = p_cntr -> next;
- X }
- X return count;
- }
- X
- /*
- X * Interpolate given point list (defined via p_cntr) using Complete
- X * Spline interpolation.
- X */
- static complete_spline_interp(p_cntr, n, t_min, t_max, tx1, ty1, tx2, ty2)
- struct cntr_struct *p_cntr;
- int n;
- double t_min, t_max, tx1, ty1, tx2, ty2;
- {
- X double dt, *tangents_x, *tangents_y;
- X int i;
- X
- X tangents_x = (double *) alloc((unsigned) (sizeof(double) * n),
- X "contour c_s_intr");
- X tangents_y = (double *) alloc((unsigned) (sizeof(double) * n),
- X "contour c_s_intr");
- X
- X if (n > 1) prepare_spline_interp(tangents_x, tangents_y, p_cntr, n,
- X t_min, t_max, tx1, ty1, tx2, ty2);
- X else {
- X free((char *) tangents_x);
- X free((char *) tangents_y);
- X return;
- X }
- X
- X dt = (t_max-t_min)/(n-1);
- X
- X add_cntr_point(p_cntr -> X, p_cntr -> Y); /* First point. */
- X
- X for (i=0; i<n-1; i++) {
- X hermit_interp(p_cntr -> X, p_cntr -> Y,
- X tangents_x[i], tangents_y[i],
- X p_cntr -> next -> X, p_cntr -> next -> Y,
- X tangents_x[i+1], tangents_y[i+1], dt);
- X
- X p_cntr = p_cntr -> next;
- X }
- X
- X free((char *) tangents_x);
- X free((char *) tangents_y);
- }
- X
- /*
- X * Routine to calculate intermidiate value of the Hermit Blending function:
- X * This routine should be called only ONCE at the beginning of the program.
- X */
- static calc_hermit_table()
- {
- X int i;
- X double t, dt;
- X
- X hermit_table = (table_entry *) alloc ((unsigned) (sizeof(table_entry) *
- X (num_approx_pts + 1)),
- X "contour hermit table");
- X t = 0;
- X dt = 1.0/num_approx_pts;
- X for (i=0; i<=num_approx_pts; i++) {
- X hermit_table[i][0] = (t-1)*(t-1)*(2*t+1); /* h00. */
- X hermit_table[i][1] = t*t*(-2*t+3); /* h10. */
- X hermit_table[i][2] = t*(t-1)*(t-1); /* h01. */
- X hermit_table[i][3] = t*t*(t-1); /* h11. */
- X t = t + dt;
- X }
- }
- X
- /*
- X * Routine to generate an hermit interpolation between two points given as
- X * two InterpStruct structures. Assume hermit_table is already calculated.
- X * Currently the points generated are printed to stdout as two reals (X, Y).
- X */
- static hermit_interp(x1, y1, tx1, ty1, x2, y2, tx2, ty2, dt)
- double x1, y1, tx1, ty1, x2, y2, tx2, ty2, dt;
- {
- X int i;
- X double x, y, vec_size, tang_size;
- X
- X tx1 *= dt; ty1 *= dt; /* Normalize the tangents according to param. t. */
- X tx2 *= dt; ty2 *= dt;
- X
- X /* Normalize the tangents so that their magnitude will be 1/3 of the */
- X /* segment length. This tumb rule guaranteed no cusps or loops! */
- X /* Note that this normalization keeps continuity to be G1 (but not C1). */
- X vec_size = sqrt(sqr(x1 - x2) + sqr(y2 - y1));
- X tang_size = sqrt(sqr(tx1) + sqr(ty1)); /* Normalize T1. */
- X if (tang_size * 3 > vec_size) {
- X tx1 *= vec_size / (tang_size * 3);
- X ty1 *= vec_size / (tang_size * 3);
- X }
- X tang_size = sqrt(sqr(tx2) + sqr(ty2)); /* Normalize T2. */
- X if (tang_size * 3 > vec_size) {
- X tx2 *= vec_size / (tang_size * 3);
- X ty2 *= vec_size / (tang_size * 3);
- X }
- X
- X for (i=1; i<=num_approx_pts; i++) { /* Note we start from 1 - first */
- X x = hermit_table[i][0] * x1 + /* point is not printed as it is */
- X hermit_table[i][1] * x2 + /* redundent (last on last section). */
- X hermit_table[i][2] * tx1 +
- X hermit_table[i][3] * tx2;
- X y = hermit_table[i][0] * y1 +
- X hermit_table[i][1] * y2 +
- X hermit_table[i][2] * ty1 +
- X hermit_table[i][3] * ty2;
- X add_cntr_point(x, y);
- X }
- }
- X
- /*
- X * Routine to Set up the 3*N mat for solve_tri_diag routine used in the
- X * Complete Spline Interpolation. Returns TRUE of calc O.K.
- X * Gets the points list in p_cntr (Of length n) and with tangent vectors tx1,
- X * ty1 at starting point and tx2, ty2 and end point.
- X */
- static prepare_spline_interp(tangents_x, tangents_y, p_cntr, n, t_min, t_max,
- X tx1, ty1, tx2, ty2)
- double tangents_x[], tangents_y[];
- struct cntr_struct *p_cntr;
- int n;
- double t_min, t_max, tx1, ty1, tx2, ty2;
- {
- X int i;
- X double *r, t, dt;
- X tri_diag *m; /* The tri-diagonal matrix is saved here. */
- X struct cntr_struct *p;
- X
- X m = (tri_diag *) alloc((unsigned) (sizeof(tri_diag) * n),
- X "contour tri_diag");
- X r = (double *) alloc((unsigned) (sizeof(double) * n),
- X "contour tri_diag2");
- X n--;
- X
- X p = p_cntr;
- X m[0][0] = 0.0; m[0][1] = 1.0; m[0][2] = 0.0;
- X m[n][0] = 0.0; m[n][1] = 1.0; m[n][2] = 0.0;
- X r[0] = tx1; /* Set start tangent. */
- X r[n] = tx2; /* Set end tangent. */
- X t = t_min;
- X dt = (t_max-t_min)/n;
- X for (i=1; i<n; i++) {
- X t = t + dt;
- X m[i][0] = dt;
- X m[i][2] = dt;
- X m[i][1] = 2 * (m[i][0] + m[i][2]);
- X r[i] = m[i][0] * ((p -> next -> X) - (p -> X)) / m[i][2]
- X + m[i][2] * ((p -> next -> next -> X) -
- X (p -> next -> X)) / m[i][0];
- X r[i] *= 3.0;
- X p = p -> next;
- X }
- X
- X if (!solve_tri_diag(m, r, tangents_x, n+1)) { /* Find the X(t) tangents. */
- X free((char *) m);
- X free((char *) r);
- X int_error("Cannt interpolate X using complete splines", NO_CARET);
- X }
- X
- X p = p_cntr;
- X m[0][0] = 0.0; m[0][1] = 1.0; m[0][2] = 0.0;
- X m[n][0] = 0.0; m[n][1] = 1.0; m[n][2] = 0.0;
- X r[0] = ty1; /* Set start tangent. */
- X r[n] = ty2; /* Set end tangent. */
- X t = t_min;
- X dt = (t_max-t_min)/n;
- X for (i=1; i<n; i++) {
- X t = t + dt;
- X m[i][0] = dt;
- X m[i][2] = dt;
- X m[i][1] = 2 * (m[i][0] + m[i][2]);
- X r[i] = m[i][0] * ((p -> next -> Y) - (p -> Y)) / m[i][2]
- X + m[i][2] * ((p -> next -> next -> Y) -
- X (p -> next -> Y)) / m[i][0];
- X r[i] *= 3.0;
- X p = p -> next;
- X }
- X
- X if (!solve_tri_diag(m, r, tangents_y, n+1)) { /* Find the Y(t) tangents. */
- X free((char *) m);
- X free((char *) r);
- X int_error("Cannt interpolate Y using complete splines", NO_CARET);
- X }
- X free((char *) m);
- X free((char *) r);
- }
- X
- /*
- X * Solve tri diagonal linear system equation. The tri diagonal matrix is
- X * defined via matrix M, right side is r, and solution X i.e. M * X = R.
- X * Size of system given in n. Return TRUE if solution exist.
- X */
- static int solve_tri_diag(m, r, x, n)
- tri_diag m[];
- double r[], x[];
- int n;
- {
- X int i;
- X double t;
- X
- X for (i=1; i<n; i++) { /* Eliminate element m[i][i-1] (lower diagonal). */
- X if (m[i-1][1] == 0) return FALSE;
- X t = m[i][0] / m[i-1][1]; /* Find ratio between the two lines. */
- X m[i][0] = m[i][0] - m[i-1][1] * t;
- X m[i][1] = m[i][1] - m[i-1][2] * t;
- X r[i] = r[i] - r[i-1] * t;
- X }
- X /* Now do back subtitution - update the solution vector X: */
- X if (m[n-1][1] == 0) return FALSE;
- X x[n-1] = r[n-1] / m[n-1][1]; /* Find last element. */
- X for (i=n-2; i>=0; i--) {
- X if (m[i][1] == 0) return FALSE;
- X x[i] = (r[i] - x[i+1] * m[i][2]) / m[i][1];
- X }
- X return TRUE;
- }
- X
- /*
- X * Generate a Bspline curve defined by all the points given in linked list p:
- X * Algorithm: using deBoor algorithm
- X * Note: if Curvekind is OPEN_CONTOUR than Open end knot vector is assumed,
- X * else (CLOSED_CONTOUR) Float end knot vector is assumed.
- X * It is assumed that num_of_points is at list 2, and order of Bspline is less
- X * than num_of_points!
- X */
- static gen_bspline_approx(p_cntr, num_of_points, order, contour_kind)
- struct cntr_struct *p_cntr;
- int num_of_points, order, contour_kind;
- {
- X int i, knot_index = 0, pts_count = 1;
- X double dt, t, next_t, t_min, t_max, x, y;
- X struct cntr_struct *pc_temp = p_cntr, *pc_tail;
- X
- X /* If the contour is Closed one we must update few things: */
- X /* 1. Make the list temporary circular, so we can close the contour. */
- X /* 2. Update num_of_points - increase it by "order-1" so contour will be */
- X /* closed. This will evaluate order more sections to close it! */
- X if (contour_kind == CLOSED_CONTOUR) {
- X pc_tail = p_cntr;
- X while (pc_tail -> next) pc_tail = pc_tail -> next;/* Find last point.*/
- X pc_tail -> next = p_cntr; /* Close contour list - make it circular.*/
- X num_of_points += order;
- X }
- X
- X /* Find first (t_min) and last (t_max) t value to eval: */
- X t = t_min = fetch_knot(contour_kind, num_of_points, order, order);
- X t_max = fetch_knot(contour_kind, num_of_points, order, num_of_points);
- X next_t = t_min + 1.0;
- X knot_index = order;
- X dt = 1.0/num_approx_pts; /* Number of points per one section. */
- X
- X
- X while (t<t_max) {
- X if (t > next_t) {
- X pc_temp = pc_temp -> next; /* Next order ctrl. pt. to blend. */
- X knot_index++;
- X next_t += 1.0;
- X }
- X eval_bspline(t, pc_temp, num_of_points, order, knot_index,
- X contour_kind, &x, &y); /* Next pt. */
- X add_cntr_point(x, y);
- X pts_count++;
- X /* As we might have some real number round off problems we must */
- X /* test if we dont produce too many points here... */
- X if (pts_count + 1 == num_approx_pts * (num_of_points - order) + 1)
- X break;
- X t += dt;
- X }
- X
- X eval_bspline(t_max - EPSILON, pc_temp, num_of_points, order, knot_index,
- X contour_kind, &x, &y);
- X /* If from round off errors we need more than one last point: */
- X for (i=pts_count; i<num_approx_pts * (num_of_points - order) + 1; i++)
- X add_cntr_point(x, y); /* Complete the contour. */
- X
- X if (contour_kind == CLOSED_CONTOUR) /* Update list - un-circular it. */
- X pc_tail -> next = NULL;
- }
- X
- /*
- X * The recursive routine to evaluate the B-spline value at point t using
- X * knot vector PKList, and the control points Pdtemp. Returns x, y after the
- X * division by the weight w. Note that Pdtemp points on the first control
- X * point to blend with. The B-spline is of order order.
- X */
- static eval_bspline(t, p_cntr, num_of_points, order, j, contour_kind, x, y)
- double t;
- struct cntr_struct *p_cntr;
- int num_of_points, order, j, contour_kind;
- double *x, *y;
- {
- X int i, p;
- X double ti, tikp, *dx, *dy; /* Copy p_cntr into it to make it faster. */
- X
- X dx = (double *) alloc((unsigned) (sizeof(double) * (order + j)),
- X "contour b_spline");
- X dy = (double *) alloc((unsigned) (sizeof(double) * (order + j)),
- X "contour b_spline");
- X /* Set the dx/dy - [0] iteration step, control points (p==0 iterat.): */
- X for (i=j-order; i<=j; i++) {
- X dx[i] = p_cntr -> X;
- X dy[i] = p_cntr -> Y;
- X p_cntr = p_cntr -> next;
- X }
- X
- X for (p=1; p<=order; p++) { /* Iteration (b-spline level) counter. */
- X for (i=j; i>=j-order+p; i--) { /* Control points indexing. */
- X ti = fetch_knot(contour_kind, num_of_points, order, i);
- X tikp = fetch_knot(contour_kind, num_of_points, order, i+order+1-p);
- X if (ti == tikp) { /* Should not be a problems but how knows... */
- X }
- X else {
- X dx[i] = dx[i] * (t - ti)/(tikp-ti) + /* Calculate x. */
- X dx[i-1] * (tikp-t)/(tikp-ti);
- X dy[i] = dy[i] * (t - ti)/(tikp-ti) + /* Calculate y. */
- X dy[i-1] * (tikp-t)/(tikp-ti);
- X }
- X }
- X }
- X *x = dx[j]; *y = dy[j];
- X free((char *) dx);
- X free((char *) dy);
- }
- X
- /*
- X * Routine to get the i knot from uniform knot vector. The knot vector
- X * might be float (Knot(i) = i) or open (where the first and last "order"
- X * knots are equal). contour_kind determines knot kind - OPEN_CONTOUR means
- X * open knot vector, and CLOSED_CONTOUR selects float knot vector.
- X * Note the knot vector is not exist and this routine simulates it existance
- X * Also note the indexes for the knot vector starts from 0.
- X */
- static double fetch_knot(contour_kind, num_of_points, order, i)
- int contour_kind, num_of_points, order, i;
- {
- X switch (contour_kind) {
- X case OPEN_CONTOUR:
- X if (i <= order) return 0.0;
- X else if (i <= num_of_points) return (double) (i - order);
- X else return (double) (num_of_points - order);
- X case CLOSED_CONTOUR:
- X return (double) i;
- X default: /* Should never happen */
- X return 1.0;
- X }
- }
- SHAR_EOF
- echo 'File gnuplot/contour.c is complete' &&
- chmod 0666 gnuplot/contour.c ||
- echo 'restore of gnuplot/contour.c failed'
- Wc_c="`wc -c < 'gnuplot/contour.c'`"
- test 41345 -eq "$Wc_c" ||
- echo 'gnuplot/contour.c: original size 41345, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/1.dat ==============
- if test ! -d 'gnuplot/demo'; then
- echo 'x - creating directory gnuplot/demo'
- mkdir 'gnuplot/demo'
- fi
- if test -f 'gnuplot/demo/1.dat' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/1.dat (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/1.dat (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/1.dat' &&
- -20.000000 -3.041676
- -19.000000 -3.036427
- -18.000000 -3.030596
- -17.000000 -3.024081
- -16.000000 -3.016755
- -15.000000 -3.008456
- -14.000000 -2.998978
- -13.000000 -2.988049
- -12.000000 -2.975310
- -11.000000 -2.960273
- -10.000000 -2.942255
- -9.000000 -2.920278
- -8.000000 -2.892883
- -7.000000 -2.857799
- -6.000000 -2.811295
- -5.000000 -2.746802
- -4.000000 -2.651635
- -3.000000 -2.498092
- -2.000000 -2.214297
- -1.000000 -1.570796
- 0.000000 0.000000
- 1.000000 1.570796
- 2.000000 2.214297
- 3.000000 2.498092
- 4.000000 2.651635
- 5.000000 2.746802
- 6.000000 2.811295
- 7.000000 2.857799
- 8.000000 2.892883
- 9.000000 2.920278
- 10.000000 2.942255
- 11.000000 2.960273
- 12.000000 2.975310
- 13.000000 2.988049
- 14.000000 2.998978
- 15.000000 3.008456
- 16.000000 3.016755
- 17.000000 3.024081
- 18.000000 3.030596
- 19.000000 3.036427
- SHAR_EOF
- chmod 0666 gnuplot/demo/1.dat ||
- echo 'restore of gnuplot/demo/1.dat failed'
- Wc_c="`wc -c < 'gnuplot/demo/1.dat'`"
- test 781 -eq "$Wc_c" ||
- echo 'gnuplot/demo/1.dat: original size 781, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/2.dat ==============
- if test -f 'gnuplot/demo/2.dat' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/2.dat (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/2.dat (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/2.dat' &&
- -20.000000 -6.083352
- -19.000000 -6.072853
- -18.000000 -6.061191
- -17.000000 -6.048162
- -16.000000 -6.033510
- -15.000000 -6.016913
- -14.000000 -5.997955
- -13.000000 -5.976098
- -12.000000 -5.950620
- -11.000000 -5.920546
- -10.000000 -5.884511
- -9.000000 -5.840556
- -8.000000 -5.785765
- -7.000000 -5.715597
- -6.000000 -5.622591
- -5.000000 -5.493603
- -4.000000 -5.303271
- -3.000000 -4.996183
- -2.000000 -4.428595
- -1.000000 -3.141593
- 0.000000 0.000000
- 1.000000 3.141593
- 2.000000 4.428595
- 3.000000 4.996183
- 4.000000 5.303271
- 5.000000 5.493603
- 6.000000 5.622591
- 7.000000 5.715597
- 8.000000 5.785765
- 9.000000 5.840556
- 10.000000 5.884511
- 11.000000 5.920546
- 12.000000 5.950620
- 13.000000 5.976098
- 14.000000 5.997955
- 15.000000 6.016913
- 16.000000 6.033510
- 17.000000 6.048162
- 18.000000 6.061191
- 19.000000 6.072853
- SHAR_EOF
- chmod 0666 gnuplot/demo/2.dat ||
- echo 'restore of gnuplot/demo/2.dat failed'
- Wc_c="`wc -c < 'gnuplot/demo/2.dat'`"
- test 781 -eq "$Wc_c" ||
- echo 'gnuplot/demo/2.dat: original size 781, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/3.dat ==============
- if test -f 'gnuplot/demo/3.dat' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/3.dat (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/3.dat (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/3.dat' &&
- -20.000000 -9.125028
- -19.000000 -9.109280
- -18.000000 -9.091787
- -17.000000 -9.072243
- -16.000000 -9.050265
- -15.000000 -9.025369
- -14.000000 -8.996933
- -13.000000 -8.964147
- -12.000000 -8.925931
- -11.000000 -8.880819
- -10.000000 -8.826766
- -9.000000 -8.760835
- -8.000000 -8.678648
- -7.000000 -8.573396
- -6.000000 -8.433886
- -5.000000 -8.240405
- -4.000000 -7.954906
- -3.000000 -7.494275
- -2.000000 -6.642892
- -1.000000 -4.712389
- 0.000000 0.000000
- 1.000000 4.712389
- 2.000000 6.642892
- 3.000000 7.494275
- 4.000000 7.954906
- 5.000000 8.240405
- 6.000000 8.433886
- 7.000000 8.573396
- 8.000000 8.678648
- 9.000000 8.760835
- 10.000000 8.826766
- 11.000000 8.880819
- 12.000000 8.925931
- 13.000000 8.964147
- 14.000000 8.996933
- 15.000000 9.025369
- 16.000000 9.050265
- 17.000000 9.072243
- 18.000000 9.091787
- 19.000000 9.109280
- SHAR_EOF
- chmod 0666 gnuplot/demo/3.dat ||
- echo 'restore of gnuplot/demo/3.dat failed'
- Wc_c="`wc -c < 'gnuplot/demo/3.dat'`"
- test 781 -eq "$Wc_c" ||
- echo 'gnuplot/demo/3.dat: original size 781, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/contours.demo ==============
- if test -f 'gnuplot/demo/contours.demo' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/contours.demo (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/contours.demo (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/contours.demo' &&
- set samples 20
- set isosamples 21
- set xlabel "X axis" -5,-2
- set ylabel "Y axis" 4,-1
- set zlabel "Z axis"
- set title "3D gnu plot demo - contour plot"
- set contour
- splot x*y
- pause -1 "Hit return to continue (1)"
- set cntrparam levels 20
- set title "3D gnu plot demo - contour plot (more contours)"
- replot
- pause -1 "Hit return to continue (2)"
- set cntrparam levels 40
- set title "3D gnu plot demo - contour plot (and again more contours)"
- replot
- pause -1 "Hit return to continue (3)"
- set cntrparam levels 10
- set title "3D gnu plot demo - contour plot on base grid"
- set contour base
- splot x**2-y**2
- pause -1 "Hit return to continue (4)"
- set title "3D gnu plot demo - contour plot on surface"
- set contour surface
- replot
- pause -1 "Hit return to continue (5)"
- set title "3D gnu plot demo - contour plot on both"
- set contour both
- replot
- pause -1 "Hit return to continue (6)"
- set contour base
- set title "3D gnu plot demo - 2 surfaces
- splot x**2*y**3, x**3*y**2
- pause -1 "Hit return to continue (7)"
- set title "3D gnu plot demo - some more interesting contours"
- splot x*y / (x**2 + y**2 + 0.1)
- pause -1 "Hit return to continue (8)"
- splot [x=-3:3] [y=-3:3] sin(x) * cos(y)
- pause -1 "Hit return to continue (9)"
- set zrange [-0.5:0.5]
- replot
- pause -1 "Hit return to continue (10)"
- set samples 6
- set isosamples 6
- set cntrparam levels 5
- set title "3D gnu plot demo - low resolution (6x6)"
- replot
- pause -1 "Hit return to continue (11)"
- set cntrparam bspline
- set title "3D gnu plot demo - low resolution (6x6) using bspline approx."
- replot
- pause -1 "Hit return to continue (12)"
- set cntrparam order 8
- set title "3D gnu plot demo - low resolution (6x6) raise bspline order."
- replot
- pause -1 "Hit return to continue (13)"
- set cntrparam linear
- set auto
- set title "3D gnu plot demo - low resolution (6x6) using linear contours."
- splot x*y
- pause -1 "Hit return to continue (14)"
- set cntrparam order 4
- set cntrparam bspline
- set title "3D gnu plot demo - low resolution (6x6) using bspline approx."
- replot
- pause -1 "Hit return to continue (15)"
- set samples 25
- set isosamples 26
- set title "3D gnu plot demo - contour of Sinc function"
- splot [-5:5.01] [-5:5.01] sin(sqrt(x**2+y**2)) / sqrt(x**2+y**2)
- pause -1 "Hit return to continue (16)"
- splot [-12:12.01] [-12:12.01] sin(sqrt(x**2+y**2)) / sqrt(x**2+y**2)
- pause -1 "Hit return to continue (17)"
- set cntrparam levels 10
- set xrange [0:15]
- set yrange [0:15]
- set auto
- set zrange [-0.6:0.6]
- set data style lines
- set title "3D gnu plot demo - contour of data grid plotting"
- set parametric
- splot "glass.dat"
- pause -1 "Hit return to continue (18)"
- set zrange [-1.2:1.2]
- set noparametric
- splot "glass.dat" using 1
- pause -1 "Hit return to continue (19)"
- set view 0,0,1
- set nosurface
- set title "3D gnu plot demo - 2D contour projection of last plot"
- replot
- pause -1 "Hit return to continue (20)"
- X
- X
- #
- # Clean up:
- #
- set surface
- set nocontour
- set cntrparam levels 5
- set cntrparam linear
- set samples 100
- set isosamples 10
- set view 60,30,1,1
- set xrange [-10:10]
- set yrange [-10:10]
- set zrange [-10:10]
- set auto
- set title "" 0,0
- set xlabel "" 0,0
- set ylabel "" 0,0
- set zlabel "" 0,0
- SHAR_EOF
- chmod 0644 gnuplot/demo/contours.demo ||
- echo 'restore of gnuplot/demo/contours.demo failed'
- Wc_c="`wc -c < 'gnuplot/demo/contours.demo'`"
- test 3088 -eq "$Wc_c" ||
- echo 'gnuplot/demo/contours.demo: original size 3088, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/controls.demo ==============
- if test -f 'gnuplot/demo/controls.demo' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/controls.demo (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/controls.demo (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/controls.demo' &&
- #
- # warning: this demo is SLOW on PCs without math coprocessors!
- #
- # From _Automatic_Control_Systems_, fourth ed., figure 6-14
- # transient response of a second-order system to a unit step input function
- #
- damp(t) = exp(-s*wn*t)/sqrt(1.0-s*s)
- per(t) = sin(wn*sqrt(1.0-s**2)*t - atan(-sqrt(1.0-s**2)/s))
- c(t) = 1-damp(t)*per(t)
- #
- # wn is natural undamped frequency
- # s is damping factor
- #
- wn = 1.0
- set xrange [0:13]
- set samples 50
- set dummy t
- #
- # plot c(t) for several different damping factors s
- #
- plot s=.1,c(t),s=.3,c(t),s=.5,c(t),s=.7,c(t),s=.9,c(t),s=1.0,c(t),s=1.5,c(t),s=2.0,c(t)
- pause -1 "Hit return to continue"
- X
- # undo what we have done
- set xrange [-10:10]
- set autoscale xy
- set samples 160
- set dummy x
- X
- SHAR_EOF
- chmod 0666 gnuplot/demo/controls.demo ||
- echo 'restore of gnuplot/demo/controls.demo failed'
- Wc_c="`wc -c < 'gnuplot/demo/controls.demo'`"
- test 712 -eq "$Wc_c" ||
- echo 'gnuplot/demo/controls.demo: original size 712, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/electron.demo ==============
- if test -f 'gnuplot/demo/electron.demo' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/electron.demo (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/electron.demo (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/electron.demo' &&
- # Electronics demo
- #
- # Bipolar Transistor (NPN) Mutual Characteristic
- Ie(Vbe)=Ies*exp(Vbe/kT_q)
- Ic(Vbe)=alpha*Ie(Vbe)+Ico
- alpha = 0.99
- Ies = 4e-14
- Ico = 1e-09
- kT_q = 0.025
- set dummy Vbe
- set grid
- set offsets
- set nolog
- set nopolar
- set samples 160
- set title "Mutual Characteristic of a Transistor"
- set xlabel "Vbe (base emmitter voltage)"
- set xrange [0 : 0.75]
- set ylabel "Ic (collector current)"
- set yrange [0 : 0.005]
- set key .2,.0045
- set format y "%.4f"
- plot Ic(Vbe)
- set format "%g"
- X
- pause -1 "Hit return to continue"
- X
- # Junction Field Effect Transistor (JFET) Mutual Characteristic
- # drain current above pinch off
- Ida(Vd)=Ido*(1-Vg/Vp)**2
- # drain current below pinch off
- Idb(Vd)=Ido*(2*Vd*(Vg-Vp)-Vd*Vd)/(Vp*Vp)
- # drain current
- Id(Vd)= (Vd>Vg-Vp) ? Ida(Vd) : Idb(Vd)
- # drain current at zero gate voltage
- Ido = 2.5
- # pinch off voltage
- Vp = -1.25
- # gate voltage
- Vg = 0
- set dummy Vd
- set nogrid
- set nokey
- set offsets 0, 1, 0, 0
- set title "JFET Mutual Characteristic"
- set xlabel "Drain voltage Vd (V)"
- set xrange [0 : 4]
- set ylabel "Drain current Id (mA)"
- set yrange [0 : 5]
- set label "-0.5 Vp" at 4.1,0.625
- set label "-0.25 Vp" at 4.1,1.4
- set label "0" at 4.1,2.5
- set label "Vg = 0.5 Vp" at 4.1,3.9
- plot Vg=0.5*Vp,Id(Vd),Vg=0.25*Vp,Id(Vd),Vg=0,Id(Vd),Vg=-0.25*Vp,Id(Vd)
- set nolabel
- X
- pause -1 "Hit return to continue"
- X
- # amplitude frequency response
- A(jw) = ({0,1}*jw/({0,1}*jw+p1)) * (1/(1+{0,1}*jw/p2))
- p1 = 10
- p2 = 10000
- set dummy jw
- set grid
- set key
- set logscale xy
- set offsets 0, 0, 0, 0
- set title "Amplitude Frequency Response"
- set xlabel "jw (radians)"
- set xrange [1.1 : 90000.0]
- set ylabel "magnitude of A(jw)"
- set autoscale y
- plot abs(A(jw))
- X
- pause -1 "Hit return to continue"
- X
- # phase frequency response
- set nolog y
- set logscale x
- set title "Phase Frequency Response"
- set ylabel "Phase of A(jw) (degrees)"
- plot 180/pi*arg(A(jw))
- X
- pause -1 "Hit return to continue"
- X
- # undo what we've done
- set dummy x
- set nogrid
- set offsets 0,0,0,0
- set title ""
- set ylabel ""
- set xlabel ""
- set xrange [-10:10]
- set autoscale xy
- set key
- set format xy "%g"
- set nolabel
- set nolog
- SHAR_EOF
- chmod 0666 gnuplot/demo/electron.demo ||
- echo 'restore of gnuplot/demo/electron.demo failed'
- Wc_c="`wc -c < 'gnuplot/demo/electron.demo'`"
- test 2065 -eq "$Wc_c" ||
- echo 'gnuplot/demo/electron.demo: original size 2065, current size' "$Wc_c"
- rm -f _shar_wnt_.tmp
- fi
- # ============= gnuplot/demo/glass.dat ==============
- if test -f 'gnuplot/demo/glass.dat' -a X"$1" != X"-c"; then
- echo 'x - skipping gnuplot/demo/glass.dat (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting gnuplot/demo/glass.dat (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'gnuplot/demo/glass.dat' &&
- #
- # 16x16 grid Glass shape. Created Using DRAWFN3D, Gershon Elber 1990.
- #
- X 0.568000 0.000000 -0.911000
- X 0.518894 0.231026 -0.911000
- X 0.380066 0.422106 -0.911000
- X 0.175522 0.540200 -0.911000
- X -0.059372 0.564888 -0.911000
- X -0.284000 0.491902 -0.911000
- X -0.459522 0.333862 -0.911000
- X -0.555588 0.118094 -0.911000
- X -0.555588 -0.118094 -0.911000
- X -0.459522 -0.333862 -0.911000
- X -0.284000 -0.491902 -0.911000
- X -0.059372 -0.564888 -0.911000
- X 0.175522 -0.540200 -0.911000
- X 0.380066 -0.422106 -0.911000
- X 0.518894 -0.231027 -0.911000
- X 0.568000 -0.000000 -0.911000
- X
- X 0.341741 0.000000 -0.905215
- X 0.312196 0.138999 -0.905215
- X 0.228669 0.253963 -0.905215
- X 0.105604 0.325015 -0.905215
- X -0.035722 0.339869 -0.905215
- X -0.170870 0.295956 -0.905215
- X -0.276474 0.200870 -0.905215
- X -0.334273 0.071052 -0.905215
- X -0.334273 -0.071052 -0.905215
- X -0.276474 -0.200870 -0.905215
- X -0.170871 -0.295956 -0.905215
- X -0.035722 -0.339869 -0.905215
- X 0.105604 -0.325015 -0.905215
- X 0.228669 -0.253963 -0.905215
- X 0.312196 -0.138999 -0.905215
- X 0.341741 -0.000000 -0.905215
- X
- X 0.212153 0.000000 -0.863178
- X 0.193812 0.086290 -0.863178
- X 0.141958 0.157661 -0.863178
- X 0.065559 0.201770 -0.863178
- X -0.022176 0.210991 -0.863178
- X -0.106077 0.183730 -0.863178
- X -0.171636 0.124701 -0.863178
- X -0.207517 0.044109 -0.863178
- X -0.207517 -0.044109 -0.863178
- X -0.171636 -0.124701 -0.863178
- X -0.106077 -0.183730 -0.863178
- X -0.022176 -0.210991 -0.863178
- X 0.065559 -0.201770 -0.863178
- X 0.141958 -0.157661 -0.863178
- X 0.193812 -0.086291 -0.863178
- X 0.212153 -0.000000 -0.863178
- X
- X 0.138097 0.000000 -0.764660
- X 0.126157 0.056169 -0.764660
- X 0.092405 0.102626 -0.764660
- X 0.042674 0.131338 -0.764660
- X -0.014435 0.137340 -0.764660
- X -0.069048 0.119595 -0.764660
- X -0.111722 0.081171 -0.764660
- X -0.135079 0.028712 -0.764660
- X -0.135079 -0.028712 -0.764660
- X -0.111722 -0.081171 -0.764660
- X -0.069048 -0.119595 -0.764660
- X -0.014435 -0.137340 -0.764660
- X 0.042674 -0.131338 -0.764660
- X 0.092405 -0.102626 -0.764660
- X 0.126157 -0.056169 -0.764660
- X 0.138097 -0.000000 -0.764660
- X
- X 0.098588 0.000000 -0.618872
- X 0.090065 0.040099 -0.618872
- X 0.065968 0.073265 -0.618872
- X 0.030465 0.093763 -0.618872
- X -0.010305 0.098048 -0.618872
- X -0.049294 0.085380 -0.618872
- X -0.079760 0.057949 -0.618872
- X -0.096434 0.020498 -0.618872
- X -0.096434 -0.020498 -0.618872
- X -0.079760 -0.057949 -0.618872
- X -0.049294 -0.085380 -0.618872
- X -0.010305 -0.098048 -0.618872
- X 0.030465 -0.093763 -0.618872
- X 0.065968 -0.073265 -0.618872
- X 0.090065 -0.040099 -0.618872
- X 0.098588 -0.000000 -0.618872
- X
- X 0.084164 0.000000 -0.452254
- X 0.076887 0.034232 -0.452254
- X 0.056317 0.062546 -0.452254
- X 0.026008 0.080044 -0.452254
- X -0.008798 0.083703 -0.452254
- X -0.042082 0.072888 -0.452254
- X -0.068090 0.049470 -0.452254
- X -0.082325 0.017499 -0.452254
- X -0.082325 -0.017499 -0.452254
- X -0.068090 -0.049470 -0.452254
- X -0.042082 -0.072888 -0.452254
- X -0.008798 -0.083703 -0.452254
- X 0.026008 -0.080045 -0.452254
- X 0.056317 -0.062546 -0.452254
- X 0.076887 -0.034233 -0.452254
- X 0.084164 -0.000000 -0.452254
- X
- X 0.092386 0.000000 -0.291706
- X 0.084399 0.037577 -0.291706
- X 0.061819 0.068656 -0.291706
- X 0.028549 0.087865 -0.291706
- X -0.009657 0.091880 -0.291706
- X -0.046193 0.080009 -0.291706
- X -0.074742 0.054303 -0.291706
- X -0.090368 0.019208 -0.291706
- X -0.090368 -0.019208 -0.291706
- X -0.074742 -0.054303 -0.291706
- X -0.046193 -0.080009 -0.291706
- X -0.009657 -0.091880 -0.291706
- X 0.028549 -0.087865 -0.291706
- X 0.061819 -0.068656 -0.291706
- X 0.084399 -0.037577 -0.291706
- X 0.092386 -0.000000 -0.291706
- X
- X 0.124988 0.000000 -0.153861
- X 0.114183 0.050837 -0.153861
- X 0.083634 0.092885 -0.153861
- X 0.038624 0.118871 -0.153861
- X -0.013065 0.124304 -0.153861
- X -0.062494 0.108243 -0.153861
- X -0.101118 0.073466 -0.153861
- X -0.122257 0.025987 -0.153861
- X -0.122257 -0.025987 -0.153861
- X -0.101118 -0.073466 -0.153861
- X -0.062494 -0.108243 -0.153861
- X -0.013065 -0.124304 -0.153861
- X 0.038624 -0.118871 -0.153861
- X 0.083634 -0.092885 -0.153861
- X 0.114183 -0.050837 -0.153861
- X 0.124988 -0.000000 -0.153861
- X
- X 0.185015 0.000000 -0.041791
- X 0.169020 0.075253 -0.041791
- X 0.123799 0.137493 -0.041791
- X 0.057173 0.175960 -0.041791
- X -0.019339 0.184002 -0.041791
- X -0.092508 0.160228 -0.041791
- X -0.149681 0.108749 -0.041791
- X -0.180972 0.038467 -0.041791
- X -0.180972 -0.038467 -0.041791
- X -0.149681 -0.108749 -0.041791
- X -0.092508 -0.160228 -0.041791
- X -0.019339 -0.184002 -0.041791
- X 0.057173 -0.175960 -0.041791
- X 0.123799 -0.137493 -0.041791
- X 0.169020 -0.075253 -0.041791
- X 0.185015 -0.000000 -0.041791
- X
- X 0.273264 0.000000 0.053395
- X 0.249639 0.111146 0.053395
- X 0.182849 0.203075 0.053395
- X 0.084443 0.259889 0.053395
- X -0.028564 0.271767 0.053395
- X -0.136632 0.236653 0.053395
- X -0.221075 0.160620 0.053395
- X -0.267292 0.056815 0.053395
- X -0.267292 -0.056815 0.053395
- X -0.221075 -0.160620 0.053395
- X -0.136632 -0.236653 0.053395
- X -0.028564 -0.271767 0.053395
- X 0.084443 -0.259889 0.053395
- X 0.182849 -0.203075 0.053395
- X 0.249639 -0.111146 0.053395
- X 0.273264 -0.000000 0.053395
- X
- X 0.384384 0.000000 0.149114
- X 0.351152 0.156343 0.149114
- X 0.257203 0.285653 0.149114
- X 0.118781 0.365570 0.149114
- X -0.040179 0.382278 0.149114
- X -0.192192 0.332886 0.149114
- X -0.310973 0.225935 0.149114
- X -0.375984 0.079918 0.149114
- X -0.375984 -0.079918 0.149114
- X -0.310973 -0.225935 0.149114
- X -0.192192 -0.332886 0.149114
- X -0.040179 -0.382278 0.149114
- X 0.118781 -0.365571 0.149114
- X 0.257203 -0.285653 0.149114
- X 0.351152 -0.156343 0.149114
- X 0.384384 -0.000000 0.149114
- X
- X 0.504089 0.000000 0.267473
- X 0.460508 0.205031 0.267473
- X 0.337301 0.374611 0.267473
- X 0.155772 0.479417 0.267473
- X -0.052692 0.501327 0.267473
- X -0.252044 0.436554 0.267473
- X -0.407816 0.296296 0.267473
- X -0.493073 0.104806 0.267473
- X -0.493073 -0.104806 0.267473
- X -0.407816 -0.296296 0.267473
- X -0.252044 -0.436554 0.267473
- SHAR_EOF
- true || echo 'restore of gnuplot/demo/glass.dat failed'
- fi
- echo 'End of part 5'
- echo 'File gnuplot/demo/glass.dat is continued in part 6'
- echo 6 > _shar_seq_.tmp
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-