25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Payments   Humor   Music

Rectangular to polar notation for iterated function sets (IFS)

The source data for an iterated function set (or system) fractal is usually stored in an .IFS data file in which the transformations are specified in rectangular notation. 

It is easier to understand the transformations intuitively when they are in polar notation. 

This program in DeSmet C tries to translate from rectangular to polar, but is only occasionally successful. See the links in the code below for better methods.  

/*	ifs2pfs.c		6-6-93 
	Copyright (C)1993 Steven Whitney.
	Initially published by http://25yearsofprogramming.com.
	Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY.

	READS DATA FROM AN .IFS FILE, TRANSLATES TO POLAR, AND OUTPUTS TO A .PFS FILE.
	THE CALCULATIONS USED HERE ONLY OCCASIONALLY DO THE TRANSFORMATION CORRECTLY.
	THE CORRECT METHOD FOR DOING THIS CONVERSION (WHICH IS CONSIDERABLY MORE COMPLEX 
	THAN SHOWN HERE) CAN BE FOUND IN IFS2PFS.CPP (POSSIBLY RELIABLE) AND WITHIN THE 
	CODE OF WSHOWFS.CPP (MOST RELIABLE), BUT I'VE NEVER BROUGHT THAT CODE BACK TO THIS H100 VERSION.

*/
#include "stdio.h"

main(argc,argv)
int argc;
char *argv[];
{
int i;
FILE *infile, *outfile;
int t;
double a, b, c, d, e, f, p;
double xr, ys, thetaangle, theta, phiangle, phi;
char buf[80];

if(argc != 2)
{
	puts("Usage:  IFS-PFS filename\n");
	puts("Omit filename extension, .IFS assumed.\n");
	puts("Program will translate from .IFS to .PFS and create filename.PFS\n");
	exit(0);
}

strcpy(buf,argv[1]);
strcat(buf,".IFS");
if(!(infile = fopen(buf,"r")))
	abort("\nFile not found\n");

strcpy(buf,argv[1]);
strcat(buf,".PFS");
if(!(outfile = fopen(buf,"w")))
	abort("Can't open output file.");

fscanf(infile,"%d\n",&t);
fprintf(outfile,"%d\n",t);

for(i = 1 ; i <= t ; i++)
{
	if(fscanf(infile,"%lf %lf %lf %lf %lf %lf %lf\n",&a,&b,&c,&d,&e,&f,&p) != 7)
		abort("\nData file corrupt.  Repair and rerun.\n");

	a *= .01; b *= .01; c*= .01; d *= .01; 		e *= 10; f *= 10;

	xr = sqrt(a * a + c * c);
	ys = sqrt(b * b + d * d);

	if(xr != 0.) theta = acos(a / xr);
	else 		 theta = 0.;
	thetaangle = theta * 180. / 3.1415926;
	if(c < 0.) thetaangle = -thetaangle;		/* PROBLEM HERE */

	if(ys != 0.) phi = acos(d / ys);
	else		 phi = 0.;
	phiangle = phi * 180. / 3.1415926;
	if(b < 0.) phiangle = -phiangle;			/* PROBLEM HERE */
	

	fprintf(outfile,"%.0f %.0f %.0f %.0f %.2f %.2f %.2f\n",
		xr*100.,ys*100.,thetaangle,phiangle,e,f,p);
	printf("%.0f %.0f %.0f %.0f %.2f %.2f %.2f\n",
		xr*100.,ys*100.,thetaangle,phiangle,e,f,p);
}
fclose(infile);
fclose(outfile);
exit(0);
}

 

 

Valid HTML 4.01 Transitional Valid CSS
Yahoo! Search
Search the web Search this site
View content labeling at ICRA.