User Tools

Site Tools


keckcaves:bifurcation

Bifurcation Demo

// orbit diagram of the logistic map
// sean whalen
 
#include <GL/GLContextData.h>
#include <GL/GLObject.h>
#include <Vrui/Application.h>
#include <Vrui/Vrui.h>
 
class LogisticExample : public Vrui::Application, public GLObject
{
private:
	struct DataItem : public GLObject::DataItem
	{
		GLuint displayListId;
 
		DataItem(void)
		{
			displayListId = glGenLists(1);
		};
 
		~DataItem(void)
		{
			glDeleteLists(displayListId, 1);
		};
	};
 
public:
	LogisticExample(int, char**, char**);
 
	void initContext(GLContextData& contextData) const;
	void display(GLContextData& contextData) const;
	double iterate(double, double) const;		
};
 
LogisticExample::LogisticExample(int argc, char** argv, char** appDefaults)
: Vrui::Application(argc, argv, appDefaults)
{
}
 
void LogisticExample::initContext(GLContextData& contextData) const
{
	DataItem* dataItem = new DataItem;
	contextData.addDataItem(this, dataItem);
 
	double parameterMinimum = 0.0;
	double parameterMaximum = 4.0;
	double steps = 1000;
	double delta = (parameterMaximum - parameterMinimum) / steps;
 
	int transients = 500;
	int iterations = 500;
 
	glNewList(dataItem->displayListId, GL_COMPILE);
		glBegin(GL_POINTS);	
 
		for(double p = parameterMinimum; p < parameterMaximum; p += delta)
		{
			double x = 0.01;
 
			for(int i = 0; i < transients; i++)
			{
				x = iterate(x, p);
			}
 
			for(int i = 0; i < iterations; i++)
			{
				x = iterate(x, p);
				glVertex2f(p, x);
			}
		}
 
		glEnd();
	glEndList();
 
	Vrui::setNavigationTransformation(Vrui::Point(0, 0, 0), 4.0);
}
 
void LogisticExample::display(GLContextData& contextData) const
{
	DataItem* dataItem = contextData.retrieveDataItem<DataItem>(this);
 
	glPushMatrix();
		glTranslatef(-2, 0, 0);
		glCallList(dataItem->displayListId);
	glPopMatrix();
}
 
double LogisticExample::iterate(double x, double r) const
{
	return r * x * (1-x);
}
 
int main(int argc, char** argv)
{
	char** appDefaults = 0;
	LogisticExample app(argc, argv, appDefaults);
	app.run();
 
        return 0;
}
keckcaves/bifurcation.txt · Last modified: 2009/10/10 03:26 by 76.20.60.65