My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

111 lines
2.8 KiB

#include <iostream>
#include <cmath>
#include <vector>
#include <cassert>
using namespace std;
#include "Projector.hpp"
#include "Canvas.hpp"
#include "myMath.hpp"
void Projector::init(double * point) {
init_vector();
project(point);
init_range();
}
void Projector::init_vector() {
project_point = new double[intern_dim];
offset = new double[intern_dim];
assert(project_point != NULL);
assert(offset != NULL);
}
void Projector::init_range() {
range_min = new double[intern_dim];
range_max = new double[intern_dim];
assert(range_min != NULL);
assert(range_max != NULL);
for ( unsigned int i = 0; i < intern_dim; i++ ) {
range_min[i] = range_max[i] = project_point[i];
}
}
void Projector::update_range(double * point) {
project(point);
for ( unsigned int i = 0; i < intern_dim; i++ ) {
if ( project_point[i] < range_min[i] ) {
range_min[i] = project_point[i];
} else if ( project_point[i] > range_max[i] ) {
range_max[i] = project_point[i];
}
}
}
void Projector::finish_range() {
// double max_dist = 0.0;
// for ( unsigned int i = 0; i < intern_dim; i++ ) {
// const double dist = range_max[i] - range_min[i];
// if ( dist > max_dist )
// max_dist = dist;
// }
//
// factor = 0.9/max_dist;
// for ( unsigned int i = 0; i < intern_dim; i++ ) {
// offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
// }
factor = canvas->size[0] / (range_max[0] - range_min[0]);
unsigned int teh_size = canvas->size[0];
for ( unsigned int i = 1; i < intern_dim; i++ ) {
double dist = range_max[i] - range_min[i];
if ( factor * dist > (double)canvas->size[i] ) {
factor = (double)canvas->size[i] / dist;
//teh_size = canvas->size[i];
cout << "crap for dim" << i << endl;
}
}
factor /= (double)teh_size;
for ( unsigned int i = 0; i < intern_dim; i++ ) {
offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
}
}
void Projector::project(double * point) {
assert(extern_dim >= 2);
project_point[0] = point[0];
project_point[1] = point[1];
}
void Projector::plot(double * point) {
project(point);
const double x = project_point[0]*factor + offset[0];
const double y = project_point[1]*factor + offset[1];
//cout << x << ", " << y << endl;
canvas->plot(x, y);
if ( even(point[2]*4.0) )
canvas->plot(x, y, 1);
else
canvas->plot(x, y, 2);
}
void Projector::output(){
cout << "Projector properties: " << endl;
cout << " factor: " << factor << endl;
for ( unsigned int i = 0; i < intern_dim; i++ ) {
cout << " dimension " << i << ": offset: " << offset[i] << ", range: [" << range_min[i] << ", " << range_max[i] << "]" << endl;
}
}