Table Of Contents

Graph IDEProgramming ► Perspective Surface

The following is a complete script for programming a 3D Surface Plot. It loads a wavy surface made from 10,000 z-values on a square grid.

/* Declarations */

double cos(double a);
double sin(double a);

@@class() PerspectiveSurface:Object

@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void) setGridXLength:(unsigned)xLength xMinimum:(double)xMinimum xMaximum:(double)xMaximum yLength:(unsigned)yLength yMinimum:(double)yMinimum yMaximum:(double)yMaximum;
@@method(public, instance) (void) appendValue:(double)aValue;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void) rotateToPhi:(double)phiAngle theta:(double)thetaAngle psi:(double)psiAngle;
@@method(public, instance) (void)release;

@@end

/* Execution block */

{
id mySurface;
int ix, iy;
double xValue, yValue, zValue;
unsigned animationCount;
double phiAngle;

mySurface = [[PerspectiveSurface alloc] init];

animationCount = [mySurface animationCount];

printf("animationCount: %d\n", animationCount);

/*
Empty the data and then append new data.
*/

[mySurface emptyData];

[mySurface setGridXLength:100 xMinimum:0.0 xMaximum:10.0 yLength:100 yMinimum:0.0 yMaximum:10.0];

for(iy = 0; iy < 100; iy++)
{
yValue = iy * 0.1;

for(ix = 0; ix < 100; ix++)
{
xValue = ix * 0.1;
zValue = 5.0 * cos(xValue) + 5.0 * sin(yValue);
[mySurface appendValue:zValue];
}
}

phiAngle = animationCount * 0.1;

[mySurface rotateToPhi:phiAngle theta:0.1 psi:0.0];

[mySurface release];

}

The general API is define in the section Graphic. The following is API description specific to the 3D Surface Plot.

@@method(public, instance) (void) setGridXLength:(unsigned)xLength xMinimum:(double)xMinimum xMaximum:(double)xMaximum yLength:(unsigned)yLength yMinimum:(double)yMinimum yMaximum:(double)yMaximum;
  Call like this:

[mySurface setGridXLength:100 xMinimum:0.0 xMaximum:10.0 yLength:100 yMinimum:0.0 yMaximum:10.0];

Sets the grid parameters. Since the grid is rectangular and uniform these are the only parameters needed to specify the grid.

@@method(public, instance) (void) appendValue:(double)aValue;
  Call like this:

[mySurface appendValue:zValue];

Appends zValue to the list of surface values. Each value must be of type double. The number of zValues appended should equal the grid x-length time y-length.

@@method(public, instance) (void)emptyData;
  Call like this:

[mySurface emptyData];

Removes (empties) all data from the graphic. Call this right before adding new data points.

@@method(public, instance) (void)appendFalseRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
  Call like this:

[mySurface appendFalseRed:0.5 green:0.4 blue:1.0 alpha:1.0];

That appends the half-cell color to the red, green, blue and alpha values of 0.5, 0.4, 1.0 and 1.0 respectively. Those values must be between 0.0 and 1.0. An alpha of 0.0 is transparent while 1.0 is completely opaque. Each argument must be a number literal or a variable (or expression) of type double. Note that this call must accompany a appendXValue:xValue yValue: call in order to synchronize the parameters that depend upon sequence index.

Note: A cell is defined by four adjacent points on the x-y grid. That cell is divided by a diagonal thus making two triangular regions. You should call this method twice with the same color to fill in the entire rectangular cell when making such false color maps.

@@method(public, instance) (void) rotateToPhi:(double)phiAngle theta:(double)thetaAngle psi:(double)psiAngle;
  Call like this:

[mySurface rotateToPhi:phi theta:theta psi:psi];

Rotates the surface plot to the phi, theta and psi angles which are yaw, pitch and roll angles respectively in units of radians.




© Copyright 1993-2022 by VVimaging, Inc. (VVI); All Rights Reserved. Please email support@vvi.com with any comments you have concerning this documentation. See Legal for trademark and legal information.