Advertisement

Line-sphere intersection... sphere vs circle vs line (beam)

Started by April 24, 2021 11:07 PM
7 comments, last by Gnollrunner 3 years, 9 months ago

I'm setting up a particle interaction ‘simulation’. It features spherical emitters, circular emitters, and beam emitters.

The full code is at: https://github.com/sjhalayka/particle

How much stronger is the interaction when it's a beam vs a sphere?

The pertinent code is:

	enum program_mode { sphere_mode, circle_mode, beam_mode };

	program_mode mode = sphere_mode;
	//program_mode mode = circle_mode;
	//program_mode mode = beam_mode;

	for (size_t i = 0; i < num_rays; i++)
	{
		double u = rand() / static_cast<double>(RAND_MAX);
		double v = rand() / static_cast<double>(RAND_MAX);

		double theta = 2 * pi * u;
		double phi = acos(2 * v - 1.0);

		vector_3 pos;

		if (mode == sphere_mode)
		{
			// get pseudorandom vector on unit sphere
			// 3D
			pos.x = cos(theta) * sin(phi);
			pos.y = sin(theta) * sin(phi);
			pos.z = cos(phi);
		}
		else if (mode == circle_mode)
		{
			// get pseudorandom vector on unit circle
			// 2D
			pos.x = cos(theta);
			pos.y = sin(theta);
			pos.z = 0;
		}
		else if (mode == beam_mode)
		{
			// 1D
			pos.x = 0;
			pos.y = 1;
			pos.z = 0;
		}

		ray_dirs.push_back(pos);

		float t = 0;

		if (line_sphere_intersect(
			vec3(0, 0, 0),
			vec3(pos.x, pos.y, pos.z),
			vec3(test_particle_pos.x, test_particle_pos.y, test_particle_pos.z),
			test_particle_radius,
			t))
		{
			intersection_positions.push_back(ray_dirs[i] * t);
		}
	}

	cout << fixed << intersection_positions.size() / static_cast<double>(num_rays) << endl;

	if (mode == sphere_mode)
	{
		// 3D
		cout << intersection_positions.size() * test_particle_pos.self_dot() << endl;
	}
	else if (mode == circle_mode)
	{
		// 2D
		cout << intersection_positions.size() * test_particle_pos.length() << endl;
	}
	else if (mode == beam_mode)
	{
		// 1D
		cout << intersection_positions.size() << endl;
	}

taby said:
How much stronger is the interaction when it's a beam vs a sphere?

What ‘interaction’ do you want to simulate? I'd think of shooting particles along the rays you have generated, to collide with some dynamic objects or other particles - but could be anything.

Advertisement

Yes exactly, the rays represent particle paths. I guess we’re interacting with photons in the long-range. Or just tabyons. Or long-range gravitons (if that’s such a thing).

Thanks for your input, man.

I find that there is an interaction constant that is 40,000 for spherical, 400,000 for circular, and 10,000,000 for the beam. So, the spherical is weaker by a factor of 25x when compared to the circle, and 250x when compared to the beam.

Gravitation, when anisotropic, is stronger. 25x greater for a disk seems like not much, but in reality, only 6x is needed to explain dark matter in disk-based systems.

hmmm… quantum physics and relativistic physics? Why not just classical mechanics? It's the physics behind ‘fun’ but hard enough :D

Yeah I’m basically assuming that the interruption of processes by photons is what gravity is all about. For a sphere and a disk there is falloff as well, so there is kinematic acceleration. for the beam there is no kinematic acceleration, just time dilation.

Advertisement

I figured it out.

https://github.com/sjhalayka/papers/blob/main/particle/bezier_escape.pdf

taby said:

Or just tabyons.

Must be cat shaped particle

This topic is closed to new replies.

Advertisement