What is NPhysics?
This is a high school research project. The goal was to build a dynamics simulator capable of solving static equilibrium problems defined by the user (a class of mechanical problems where the objective is to find the balance of forces in a system). Once the system is solved, the program runs a real-time simulation treating the situation as dynamic and checks whether motion actually occurs. Both the problem setup and the simulation take place in a graphical, easy-to-use environment.
Example simulations
Robotic arm example
Motor torque calculation
Water simulation
Applications
The program solves problems efficiently that would otherwise require physical tests, most of which would be destructive. That said, it would not be fair or sensible to treat any software as a replacement for empirical testing of a real structure. What it does offer is a lot of flexibility: you can simulate a wide variety of structures in seconds with no material cost.
The other goal was to make the program accessible to anyone interested in mechanics, and to spark interest in mechanics, physics, and science in general for a broader audience.
Installation
NPhysics is a portable program. No installer is needed and it can be run directly from its folder. You can either download the latest stable compiled release from GitHub or build the project yourself.
Download
The program can be downloaded from the GitHub releases page in its latest stable compiled version. Each release includes 3 variants:
- NPhysics.zip (extract with any decompression tool)
- NPhysics.7z (extract with 7z)
- NPhysics.exe (self-extracting Windows executable)
NPhysics is written in Java, which makes it cross-platform. It runs on any Linux distribution, Windows, and macOS, as long as JRE or JDK is installed.
After downloading and extracting, run NPhysics.jar. By default the program runs in fullscreen, but it can be run in windowed mode using window.bat (Windows only).
You can also launch it from a terminal: java -jar NPhysics.jar for fullscreen, java -jar NPhysics.jar window for windowed mode.
Building from source
If you want the latest commit rather than a stable release, you can compile directly from the repository. The project uses Gradle. To build the binaries, run the following from the repository root:
gradlew desktop:dist
This compiles the program and copies the output to desktop/build/libs. After building, copy everything from desktop/assets into the same folder as the compiled output.
Running the compiled build
To run the compiled program: java -jar desktop1.0
Libraries used: LibgdxEarcut4jJTS
User Guide
This section is a short introductory guide covering the main features: from creating simple objects to adding springs, pulleys, joints, motors, water, and more. Each section is accompanied by a video showing the steps.
First steps
This section covers creating simple objects, modifying their physical properties, and handling the basic entities in the design phase.
By default the program uses English. To change the language, press F1 to open the program settings, adjust the Language value using the scrollbar, and apply. A restart is required for the change to take effect.
Once the language is set, the program is ready to use. Reading the guide is recommended but not required to get started.
UI layout
When the program opens, it shows a grid on a light blue background (the design area, where you define objects and their relationships). There are 3 main menus:
- The top bar for switching between the design phase and the simulation phase
- The side menu for selecting the active tool in the design phase
- The bottom bar with a button to clear all objects and a toggle for snap-to-grid
Hovering over any button in the side tool menu shows a short description of its function.
Moving the view
The default tool is the mouse tool, which lets you select objects and move the view. Click and drag on an empty area to pan the view. Press A over any point to move the reference axis there.
Creating a simple object
To create a polygon body, use the polygon creation tool. Click on the plane to place vertices one by one, then click back on the first vertex to close the shape.
If the desired position is not an existing point, the program creates it automatically.
Once the object is created, press Q to open its properties panel. The available options are:
- Simulator options
- Precise simulation for fast objects (how strict the simulation should be in extreme cases; leave unchecked in general)
- State (Dynamic, Kinematic, Static)
- Linear velocity (m/s)
- Linear velocity X
- Linear velocity Y
- Material properties
- Mass (kg)
- Density (kg/m^2)
- Friction (coefficient, 0 to 1)
- Restitution (coefficient, 0 to 1)
The precise simulation option for fast objects should only be applied to objects that behave unexpectedly (like passing through other objects). It tells the simulator to be more thorough when computing collisions.
Linear velocity sets the initial velocity of the object.
After changing any value, press Enter to apply.
With an object selected, press C over any point to create a duplicate.
Simulation
Once the objects are placed, switch to simulation mode using the button in the top bar. The background turns black and the simulation starts. In this mode you can grab objects with the mouse and interact with them. The program displays the forces acting on each object (excluding collision forces).
| Force type | Color |
|---|---|
| User-defined forces | Red |
| Gravity | Yellow |
| Reaction forces | Green |
| Rope tension | Orange |
You can also display the linear momentum of objects by pressing I (disabled by default). When many objects are simulated at once the display can get cluttered. Press U to hide all arrows and values and dim all objects, showing only the selected object's information highlighted.
To return to design mode, use the button in the top bar.
Defining Forces
After defining an object in the design phase you can add forces that will be applied during the simulation. To create a force, first select the object in design mode, then use the force creation tool.
Click on the plane to set the force origin, then click again to set the end point of the force vector. This is just a visual way to define the direction; to set the magnitude precisely, select the vector and edit its properties in the panel that appears. The selected vector is highlighted in yellow.
- Set origin vector Set the coordinates of the vector origin relative to the reference axis
- Set force vector Set the vector components, magnitude, and angle (cartesian or polar)
- Set this force as unknown Marks this vector as an unknown (explained later)
- Vector type Defines how the vector's position evolves during simulation:
- World keeps the vector applied at the same world position (not relative to the object)
- Translation-relative makes the origin relative to the object's position and angle, but the direction stays fixed
- Relative makes both the origin and direction relative to the object's position and rotation
After editing, close the panel with Close to see the force acting in the simulation. To delete a force, select it and press Delete.
Joints
The program supports several types of joints for more complex scenarios. Here is the full list of joints and tools for defining relationships between two objects.
To create a joint, select the required objects first. Some joints require one selected object, others require two. To select two objects at once, hold Shift and click both.
Some joints have editable properties. Select the joint to open its properties panel.
In simulation mode, joints draw their reaction forces (in green) at the appropriate point.
- Axes and motors
- Prismatic rails
- Ropes
- Springs
- Pulleys
Axes and motors
Fixed axes are the simplest joint to place. Select the desired object and the side panel for single-object tools will appear. The first tool is axis/motor creation (the same tool handles both; whether it acts as an axis or a motor depends on the torque value). Once the tool is selected, click where you want the support point.
The properties panel has two fields for position relative to the reference axis and two for physical properties. The first is motor torque: a value of 0 makes it act as a plain axis, anything else makes it a motor. The second sets the maximum angular velocity the motor will spin the body (rad/s).
Prismatic rails
Prismatic rails constrain an object's movement to a single axis. Select the object and the prismatic rail creation tool. Placement works the same way as axes.
Prismatic rails draw a red line on their icon indicating the allowed movement axis. The properties panel has two fields for joint position and one for the rail angle.
Ropes
Ropes connect two objects and set a maximum distance between their two support points (that is their only physical effect). To place a rope, select both objects, then choose the rope tool from the joint menu that appears. Click the support point on the first object, then on the second (order does not matter). Once placed, the rope can be adjusted by moving its support points.
Ropes have no editable properties.
Springs
Springs connect two objects similarly to ropes, but instead of tension above a threshold, springs apply a force to one of the objects that is proportional to the distance between them: F = -kx (Hooke's law). Adding a spring is straightforward. Select two objects as with ropes, but choose the spring creation tool. Click one support point on each object. The spring is created.
Once created, you can set its spring constant k (N/m) in the properties panel.
One of the two objects must be set to static so the simulation knows which one receives the force. Combining a spring with a prismatic rail ensures the object moves along the line connecting the two support points.
Pulleys
To create a pulley between two objects you first need two support points, created with the point creation tool.
Then select both objects and choose the pulley tool. Click a point on the first object, then its support point, then the support point of the second object, then a point on the second object. After that sequence the pulley is created.
The pulley properties panel has a field to set the transmission ratio.
Static solver
The program can calculate the exact value a force must have, applied at a given point and direction, to produce a static equilibrium in the target object. Create a force to use as the unknown, define its direction, and the program will find the value that satisfies the equilibrium conditions.
Due to how the algorithm works, it can only solve situations where the torque generated by the force is relevant. For example, if all forces (including the unknown) are applied at the same point, the program cannot find a solution. Most interesting problems do not fall into that category and the algorithm handles them fine. When a problem involves multiple unknowns and objects, it is recommended to run the algorithm in steps, solving the forces with the least influence first.
Forces marked as unknown are rendered in red. To solve them, either press P with the object selected or click the Solve button in the object's properties panel.
