|
From: <and...@us...> - 2013-11-24 22:01:21
|
Revision: 12747
http://sourceforge.net/p/plplot/code/12747
Author: andrewross
Date: 2013-11-24 22:01:17 +0000 (Sun, 24 Nov 2013)
Log Message:
-----------
Update C++ example 22 following recent changes to C version.
Modified Paths:
--------------
trunk/examples/c++/x22.cc
Modified: trunk/examples/c++/x22.cc
===================================================================
--- trunk/examples/c++/x22.cc 2013-11-24 21:41:37 UTC (rev 12746)
+++ trunk/examples/c++/x22.cc 2013-11-24 22:01:17 UTC (rev 12747)
@@ -32,13 +32,32 @@
using namespace std;
#endif
+//
+// Global transform function for a constriction using data passed in
+// This is the same transformation used in constriction.
+//
+void
+transform( PLFLT x, PLFLT y, PLFLT *xt, PLFLT *yt, PLPointer data )
+{
+ PLFLT *trdata;
+ PLFLT xmax;
+
+ trdata = (PLFLT *) data;
+ xmax = *trdata;
+
+ *xt = x;
+ *yt = y / 4.0 * ( 3 - cos( M_PI * x / xmax ) );
+}
+
+
class x22 {
public:
x22( int, const char ** );
private:
void circulation();
- void constriction();
+ void constriction( int astyle );
+ void constriction2();
void potential();
void f2mnmx( PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmin, PLFLT *fmax );
@@ -49,7 +68,7 @@
PLFLT **u, **v;
PLcGrid2 cgrid2;
- int nx, ny;
+ int nx, ny, nc, nseg;
};
// Vector plot of the circulation about the origin
@@ -93,12 +112,13 @@
// Vector plot of flow through a constricted pipe
void
-x22::constriction()
+x22::constriction( int astyle )
{
int i, j;
PLFLT dx, dy, x, y;
PLFLT xmin, xmax, ymin, ymax;
PLFLT Q, b, dbdx;
+ char title[80];
dx = 1.0;
dy = 1.0;
@@ -111,17 +131,17 @@
Q = 2.0;
for ( i = 0; i < nx; i++ )
{
+ x = ( i - nx / 2 + 0.5 ) * dx;
for ( j = 0; j < ny; j++ )
{
- x = ( i - nx / 2 + 0.5 ) * dx;
y = ( j - ny / 2 + 0.5 ) * dy;
cgrid2.xg[i][j] = x;
cgrid2.yg[i][j] = y;
- b = ymax / 4.0 * ( 3 - cos( M_PI * x / xmax ) );
+ b = ymax / 4.0 * ( 3.0 - cos( M_PI * x / xmax ) );
if ( fabs( y ) < b )
{
dbdx = ymax / 4.0 * sin( M_PI * x / xmax ) *
- y / b;
+ M_PI / xmax * y / b;
u[i][j] = Q * ymax / b;
v[i][j] = dbdx * u[i][j];
}
@@ -134,12 +154,72 @@
}
pls->env( xmin, xmax, ymin, ymax, 0, 0 );
- pls->lab( "(x)", "(y)", "#frPLplot Example 22 - constriction" );
+ sprintf( title, "#frPLplot Example 22 - constriction (arrow style %d)", astyle );
+ pls->lab( "(x)", "(y)", title );
pls->col0( 2 );
pls->vect( u, v, nx, ny, -0.5, plstream::tr2, (void *) &cgrid2 );
pls->col0( 1 );
}
+//
+// Vector plot of flow through a constricted pipe
+// with a coordinate transform
+//
+void
+x22::constriction2( void )
+{
+ int i, j;
+ PLFLT dx, dy, x, y;
+ PLFLT xmin, xmax, ymin, ymax;
+ PLFLT Q, b, dbdx;
+ PLFLT clev[nc];
+
+ dx = 1.0;
+ dy = 1.0;
+
+ xmin = -nx / 2 * dx;
+ xmax = nx / 2 * dx;
+ ymin = -ny / 2 * dy;
+ ymax = ny / 2 * dy;
+
+ pls->stransform( transform, ( PLPointer ) & xmax );
+
+ Q = 2.0;
+ for ( i = 0; i < nx; i++ )
+ {
+ x = ( i - nx / 2 + 0.5 ) * dx;
+ for ( j = 0; j < ny; j++ )
+ {
+ y = ( j - ny / 2 + 0.5 ) * dy;
+ cgrid2.xg[i][j] = x;
+ cgrid2.yg[i][j] = y;
+ b = ymax / 4.0 * ( 3 - cos( M_PI * x / xmax ) );
+ u[i][j] = Q * ymax / b;
+ v[i][j] = 0.0;
+ }
+ }
+
+ for ( i = 0; i < nc; i++ )
+ {
+ clev[i] = Q + i * Q / ( nc - 1 );
+ }
+
+ pls->env( xmin, xmax, ymin, ymax, 0, 0 );
+ pls->lab( "(x)", "(y)", "#frPLplot Example 22 - constriction with plstransform" );
+ pls->col0( 2 );
+ pls->shades( (const PLFLT * const *) u, nx, ny, NULL,
+ xmin + dx / 2, xmax - dx / 2, ymin + dy / 2, ymax - dy / 2,
+ clev, nc, 0, 1, 1.0, plstream::fill, 1, NULL, NULL );
+ pls->vect( (const PLFLT * const *) u, (const PLFLT * const *) v, nx, ny,
+ -0.5, plstream::tr2, (void *) &cgrid2 );
+ // Plot edges using plpath (which accounts for coordinate transformation) rather than plline
+ pls->path( nseg, xmin, ymax, xmax, ymax );
+ pls->path( nseg, xmin, ymin, xmax, ymin );
+ pls->col0( 1 );
+
+ pls->stransform( NULL, NULL );
+}
+
// Vector plot of the gradient of a shielded potential (see example 9)
void
x22::potential()
@@ -263,12 +343,11 @@
bool fill;
// Set of points making a polygon to use as the arrow
- PLFLT arrow_x[6] = { -0.5, 0.5, 0.3, 0.5, 0.3, 0.5 };
- PLFLT arrow_y[6] = { 0.0, 0.0, 0.2, 0.0, -0.2, 0.0 };
- PLFLT arrow2_x[6] = { -0.5, 0.3, 0.3, 0.5, 0.3, 0.3 };
- PLFLT arrow2_y[6] = { 0.0, 0.0, 0.2, 0.0, -0.2, 0.0 };
+ PLFLT arrow_x[6] = { -1.0, 1.0, 0.6, 1.0, 0.6, 1.0 };
+ PLFLT arrow_y[6] = { 0.0, 0.0, 0.4, 0.0, -0.4, 0.0 };
+ PLFLT arrow2_x[6] = { -1.0, 0.6, 0.6, 1.0, 0.6, 0.6 };
+ PLFLT arrow2_y[6] = { 0.0, 0.0, 0.4, 0.0, -0.4, 0.0 };
-
// Create new plstream
pls = new plstream();
@@ -282,6 +361,8 @@
nx = 20;
ny = 20;
+ nc = 11;
+ nseg = 20;
// Allocate arrays
pls->Alloc2dGrid( &cgrid2.xg, nx, ny );
@@ -300,14 +381,20 @@
// Set arrow style using arrow_x and arrow_y then
// plot using these arrows.
pls->svect( arrow_x, arrow_y, narr, fill );
- constriction();
+ constriction( 1 );
// Set arrow style using arrow2_x and arrow2_y then
// plot using these filled arrows.
fill = true;
pls->svect( arrow2_x, arrow2_y, narr, fill );
- constriction();
+ constriction( 2 );
+ constriction2();
+
+ // Reset arrow style to the default by passing two
+ // NULL arrays
+ pls->svect( NULL, NULL, 0, 0 );
+
potential();
pls->Free2dGrid( cgrid2.xg, nx, ny );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|