Pasted Graphic 1
An example showing the PHVectorField object, with a user defined color coloring scheme for the field. Click on the link above to view a pdf rendered version of the same output.
Here is the AppController code :
Interface from AppController.h :
@interface AppController : NSObject {
IBOutlet PHGraphView* graphView;
PHxAxis* xaxis;
PHyAxis* yaxis;
PHAxisSystem* axisSystem;
PHCurve* forwardEuler;
PHVectorField* vectorField;
double xData[10000];
double yData[10000];
}
and AppController.m :
int vectorFieldFunction(double x, double y, double *vectX, double *vectY)
{
*vectX = y;
*vectY = -x;
return 0;
}
void colorScheme(double x,double y, float *Red, float *Green, float *Blue, float *Alpha)
{
*Red = x;
*Green = y;
*Blue = 0;
*Alpha = 1;
}
@implementation AppController
-(id)init
{
[super init];
return self;
}
-(void)awakeFromNib
{
xaxis=[[PHxAxis alloc] initWithStyle: 0];
[xaxis setMinimum:-1.5 maximum:1.5];
yaxis=[[PHyAxis alloc] initWithStyle: 0];
[yaxis setMinimum:-1.2 maximum:1.2];
[graphView addPHxAxis:xaxis];
[graphView addPHyAxis:yaxis];
[graphView setMouseEventsMode:PHCompositeZoomAndDrag];
xData[0]=0.1;
yData[0]=0.1;
int i;
double h = 0.02;
for (i=1; i<</span>10000; i++)
{
xData[i]=xData[i-1]+h*yData[i-1];
yData[i]=yData[i-1]-h*xData[i-1];
}
axisSystem = [[PHAxisSystem alloc] initWithXAxis:xaxis yAxis:yaxis];
vectorField = [[PHVectorField alloc] initWithXAxis:xaxis
yAxis:yaxis function: &vectorFieldFunction];
[vectorField setColorFunction:colorScheme];
forwardEuler = [[PHCurve alloc] initWithXData:xData yData:yData
numberOfPoints:10000 xAxis:xaxis yAxis:yaxis];
[forwardEuler setColor:[NSColor blueColor]];
[vectorField setXGrid:20 yGrid:20];
[graphView addPHGraphObject:forwardEuler];
[graphView addPHGraphObject:vectorField];
[graphView addPHGraphObject:axisSystem];
[graphView setDelegate:self];
}
@end