The more fractional the dimension, the less fractal the curve:
#include "main.h"
int main(int argc, char** argv)
{
cout << setprecision(20) << endl;
srand(0);
const double start_dim = 2.001;
const double end_dim = 3;
const size_t dim_res = 3;
const double dim_step_size = (end_dim - start_dim) / (dim_res - 1);
for (double D = start_dim; D <= end_dim; D += dim_step_size)
{
threeD_oscillators.clear();
normals.clear();
threeD_line_segments.clear();
threeD_line_segments_intersected.clear();
const size_t n = 1000000;
//if (dimension <= 2)
// dimension = 2.001;
//else if (dimension > 3)
// dimension = 3;
const double disk_like = 3 - D;
const double falloff_exponent = 2 - disk_like;
// Start with pseudorandom oscillator locations
for (size_t i = 0; i < n; i++)
{
vector_3 r = RandomUnitVector();
threeD_oscillators.push_back(r);
}
// Spread the oscillators out, so that they are distributed evenly across
// the surface of the ellipsoid emitter
for (size_t i = 0; i < n; i++)
{
vector_3 ring;
ring.x = threeD_oscillators[i].x;
ring.y = 0;
ring.z = threeD_oscillators[i].z;
vector_3 s = slerp(threeD_oscillators[i], ring, disk_like);
threeD_oscillators[i] = s;
}
// Get position on oblate ellipsoid
for (size_t i = 0; i < n; i++)
{
vector_3 vec = threeD_oscillators[i];
const vector_4 rv = RayEllipsoid(vector_3(0, 0, 0), vec, vector_3(1.0, 1.0 - disk_like, 1.0));
threeD_oscillators[i] = vector_3(rv.y, rv.z, rv.w);
}
// Get position and normal on prolate ellipsoid
for (size_t i = 0; i < n; i++)
{
const vector_4 rv = RayEllipsoid(vector_3(0, 0, 0), threeD_oscillators[i], vector_3(1.0 - disk_like, 1.0, 1.0 - disk_like));
vector_3 collision_point = vector_3(rv.y, rv.z, rv.w);
vector_3 normal = EllipsoidNormal(collision_point, vector_3(1.0 - disk_like, 1.0, 1.0 - disk_like));
normals.push_back(normal);
line_segment_3 ls;
ls.start = threeD_oscillators[i];
ls.end = threeD_oscillators[i] + normals[i];// *1e30;
threeD_line_segments.push_back(ls);
}
//vector_3 receiver_pos(10, 0, 0);
//size_t collision_count = get_intersecting_line_count(receiver_pos, 1.0, dimension, false);
string filename = to_string(D) + ".txt";
ofstream out_file(filename.c_str());
//// Get intersecting lines
const double start_distance = 10;
const double end_distance = 100;
const size_t distance_res = 100;
const double distance_step_size = (end_distance - start_distance) / (distance_res - 1);
for (double r = start_distance; r <= end_distance; r += distance_step_size)
{
vector_3 receiver_pos(r, 0, 0);
size_t collision_count = get_intersecting_line_count(receiver_pos, 1.0, D, true);
// todo: get gradient of collision count at r
cout << "D " << D << " " << r << " " << collision_count * pow(receiver_pos.x, falloff_exponent) << endl;
out_file << r << " " << collision_count * pow(receiver_pos.x, falloff_exponent) << endl;
}
out_file.close();
//vector_3 receiver_pos(100, 0, 0);
//size_t collision_count = get_intersecting_line_count(receiver_pos, 1.0, D, true);
//cout << D << " " << collision_count << endl;
}
return 0;
}