Skip to content

Simultaneous attractive and repulsive forces in the same particle #85

@KhadrasWellun

Description

@KhadrasWellun

Hi! I want a particle of a certain colour to attract and repel a particle of another colour simultaneously, on different beams and with different intensities. In the original application, a particle either attracts or repels another particle, depending on the sign of the intensity of the interaction force.
I started by defining interactions as follows:
void interaction(std::vector* Group1, const std::vector* Group2, float G, float Gradius, float A, float Aradius, float viscosity, float Gprobability, float Aprobability);
"G" would be "powerSlider_a_" for pull force, "Gradius" would be "vSlider_a_" for pull force, "A" would be "powerSlider_r_" for repelling force, "Aradius" would be "vSlider_r_" for repelling force.
Defining interactions would be of the form:
if (numberSliderR > 0) interaction(&green, &red, powerSlider_a_GR, vSlider_a_GR, powerSlider_r_GR, vSlider_r_GR, viscosityG, probability_a_GR, probability_r_GR);

However, I have no idea how the calculation of forces and velocities should be defined.

I try to defined:

void ofApp::interaction(std::vector* Group1, const std::vector* Group2, const float G, const float Gradius, const float A, const float Aradius, const float viscosity, const float Gprobability, const float Aprobability)
{
const float g = G / -100; //Gravity coefficient
const float a = A / 100; //Anti-Gravity coefficient
const auto group1size = Group1->size();
const auto group2size = Group2->size();
const bool radius_toggle = radiusToogle;

But I don't know if it's good.

Then I modified this:
//Calculate the force in given bounds.
if ((r < (Gradius * Gradius - Aradius * Aradius) || radius_toggle) && r != 0.0F)
{
fx += (dx / std::sqrt(dx * dx + dy * dy));
fy += (dy / std::sqrt(dx * dx + dy * dy));
}
}

				//Calculate new velocity
				p1.vx = (p1.vx + (fx * (g + a))) * (1 - viscosity);
				p1.vy = (p1.vx + (fx * (g + a))) * (1 - viscosity) + worldGravity;

But I don't know if it's good.

It must be kept in mind that each type of force has its intensity and range of action and this must be clearly defined in the application.

There would be three situations:
when Gradius > Aradius;
when Gradius = Aradius;
when Gradius < Aradius.

For each of them I think the formulas for force and velocity should be defined.

For example: Blue can attract White with an intensity of 20, on a radius of 100, and at the same time repel White with an intensity of 30 but on a radius of 40. Then White can attract Blue with an intensity of 30 on a radius of 70, but simultaneously repel it with an intensity of 50 on a radius of 60. So White can be caught by the attraction of Blue but cannot approach it at less than 60, because it repels Blue with an intensity of 50 which is greater than the attraction of 30 it has to Blue at a radius of 70. At a distance of 60, there is a neutral force of zero intensity between Blue and White.

Any ideas? Any help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions