Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:16:59+00:00 2026-05-22T01:16:59+00:00

I am a total beginner in both simulations so this question might be silly.

  • 0

I am a total beginner in both simulations so this question might be silly. If so, please feel free to edit it. I am trying to simulate the following scenario in Python. I randomly place a few small particles in a 2D field with fixed dimentions. Each particle has a radius of effect r. If the first particle has the second one within its radius of effect, then a force has to be applied on both the particles (the effect that the first one has on the second and vice versa) and my force function is defined as:

f(i,j)_n = (r - |pi_n - pj_n|)((pj_n - pi_n)/|pi_n - pj_n|)

where n is the time step currently, pi_n represents the position of i at time step n and || represents magnitude calculation and (pj_n - pi_n) represents vector subtraction.

I was wondering if there are any libraries that simplify this stuff for me. All I need is basically the following:

time-step particle position(x,y)

Does anyone have some suggestions for me please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:17:00+00:00Added an answer on May 22, 2026 at 1:17 am

    I really like the pymunk physics library, a wrapper for the chipmunk physics library.

    First of all, the library needs to be initialized:

    import pymunk
    pymunk.init_pymunk()
    space = pymunk.Space()
    space.gravity = (0.0, -100.0)
    

    To achieve something the likes you have requested you have to create a Body and a Circle shape for each particle you wish to create.

    mass = 1
    radius = 14
    inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
    body = pymunk.Body(mass, inertia)
    x, y = random.randint(0, 200), random.randint(0, 200)
    body.position = x, 550
    shape = pymunk.Circle(body, radius, (0,0))
    shape.sensor = True
    space.add(body, shape)
    

    The particles will not collide with each other, beacause the sensor flag is set to True. The radius is now somewhat of an area of influence.

    Now, we create a callback function for particles which have an overlapping area of influence:

    def near_callback(space, arbiter, *args, **kwargs):
        body_i = arbiter.shapes[0].body
        body_j = arbiter.shapes[1].body
    
        # calculate the forces force_i and force_j with your formula
        ...
    
        body_i.apply_force(force_i)
        body_j.apply_force(force_j)
    

    The callback is set in the space:

    space.set_default_collision_handler(near_callback, near_callback, None, None, None)
    

    Of course, the space has to be “stepped” for each time-frame:

    space.step(dt)
    

    I hope this was somewhat understandable and helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Java and am following the Eclipse Total Beginner's Tutorials .
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input
I am a total beginner in JS/XML. I have this simple code that needs
I am a complete, total beginner in programming, although I do have knowledge of
Total beginner in WPF so bear with me. I building a proof of concept
Ok I am a total beginner with the Solaris Operating system and I need
I'm a newbie to both R and LaTeX and have just recently found how
I understand that the title might not be descriptive enough, but I'm making a
I've heard a few debates in the past over which is more mature: RubyCocoa
I need to create a class which calculates the distance between two points. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.