Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Rope Simulation
Weighting: 12%
Total mark: 100
Instruction
All homework assignments must be completed individually. We encourage you to discuss
the assignments with other students. However, you should not share any of your codes
with anyone else. Each student is responsible for implementing the assignment on their
own. You may assist others in debugging their codes, but you should not copy and paste.
ANU is using Turnitin to detect possible duplications. Consulting with previous year stu-
dents who enrolled in this course on specific assignments is also not allowed. You may
use the internet as a resource for learning the materials, but you should not borrow any
existing codes found online.
You will submit a single ZIP file as your submission, which must contain the following files:
• All source codes (ending in .h, or .hpp, or .cpp), and CMakeLists.txt. Please include all
needed source codes for successful compilation. Please also remove all intermediate
files (such as .vscode and build) that are not needed for the compilation.
• A PDF format HW5 Report using the given template with a signed Declaration of
Originality statement.
Your ZIP file must be named as “COMPX610_2024_HW5_UID.zip”. Replace ‘X’ with 4
or 8. Replace the UID with your Uxxxxxxxx. Please submit your ZIP file to Wattle before
the deadline. Late submission will lead to a penalty as per the ANU policy. Later-than-
one-week submission will not be accepted, which may result in zero marks unless a pre-
approval for special consideration is obtained in writing before the submission deadline.
Overview of CLab-5:
We will implement a rope simulator subject to gravity and expand it into a cloth simulator
that also subject to collision detection. To simulate, you should use the mass spring model
discussed in our lectures and in the readings.
1
A fully operational skeletal code framework is provided for this lab. You are required to
modify or insert specific functions within the framework, as per the following requirements.
Preliminary
Before commencing, familiarize yourself with the framework’s structure and functionalities
as outlined below:
Mass Spring Model
• mass.h : Defines a mass point with some physical properties.
• spring.h : Defines a spring connecting two mass points.
• rope.h , rope.cpp : Manages a collection of masses and springs to simulate a rope.
• cloth.h , cloth.cpp : Similar to Rope , but models a grid of masses and springs to
simulate cloth physics.
Collision
• collider.h : An abstract base class that defines the interface for collidable objects.
• box.h : A specific type of collider that represents a rectangular bounding box.
Render
• rasterizer.h , rasterizer.cpp : Draw primitives and objects with wireframes.
• transforms.h , transforms.cpp : Provides transformation matrices (rotation, trans-
lation, view, projection).
Entry Point and Setup
• task{n}.cpp : Entry point for task{n}.
• CMakeLists.txt : Provides configuration for the CMake build process.
Compilation and Execution
Compile and run your project with the following commands:
1 cd build
2 cmake ..
3 make
4 ./taskN # replace N with an integer number of task 1/2/3/4/5
2
Tasks requirements
For each task n, you should complete all functions that require filling in, as specified in the
instructions below. Make sure your code can compile and run without errors.
Your report should contain your explanation/discussion together with any necessary im-
ages to support your explanation/discussion if a task requires you to explain/compare/de-
scribe/assess/etc. Each image in your report must be mentioned in the text. When you
mention an image, there must be a clear reference to the image.
Task1: Constraints on connecting ropes (15 marks)
Implement the constructor for the Rope class in rope.cpp . This constructor should cre-
ate a new Rope object, which is defined by two endpoints at start and end positions,
respectively, and consists of num_nodes nodes (see below).
1 Rope::Rope(Eigen::Vector3f start , Eigen::Vector3f end, int
num_nodes , float node_mass , float k, float damping_factor ,
2 std::vector fixed_nodes)
• start and end: Eigen::Vector3f positions of the rope’s starting and ending points.
• num_nodes: The total number of nodes in the rope, including the endpoints.
• node_mass: The mass assigned to each node.
• k: The spring constant, i.e., the stiffness of the springs connecting the nodes.
• damping_factor: A coefficient that reduces the velocity of nodes over time.
• pinned_nodes: A vector of indices specifying which nodes are stationary.
Upon constructing a Rope object, you are responsible for implementing two key functions:
• initializeMasses : This function initializes all nodes in the rope. You will iterate
through the number of nodes, calculate their positions linearly between start and
end , and instantiate Mass objects for each. Specific nodes can be set as fixed based
on the fixed_nodes array.
3
• linkSprings : This function connects consecutive nodes with springs. You must cre-
ate a new Spring for each pair of adjacent nodes using the provided spring constant
k .
Run ./task1 , you should see the string drawn on the screen, but it should remain sta-
tionary.
Please explain your implementation with the screenshot of your code in your report.
Task2: Explicit/semi-implicit Euler’s law (30 marks)
Hooke’s law states that the force between two masses connected by a spring is propor-
tional to the distance between them. Namely:
fb→a = −ks · b− a‖b− a‖ · (‖b− a‖ − l)
where:
• fb→a is the force exerted by mass b on mass a.
• ks is the spring constant.
• b− a is the vector from mass a to mass b.
• ‖b− a‖ is the magnitude of the vector from mass a to mass b.
• l is the natural length of the spring.
First, implement Hooke’s law: Iterate through all the springs and apply the correct spring
force to the masses at the ends of the spring. Ensure that the force is applied in the correct
direction. For each mass, sum up all the spring forces acting on it.
Second, once all spring forces have been calculated, apply the laws of physics to each
mass using the formula:
a = F/m
vt+1 = vt + at ·∆t
xt+1 = xt + vt ·∆t (explicit method)
xt+1 = xt + vt+1 ·∆t (semi-implicit method)
4
where vt+1 is the updated velocity, vt is the current velocity, at is the current accelera-
tion (F/m), ∆t is the time step, and xt+1 and xt are the updated and current positions,
respectively.
Hints: Masses on the rope will be subject to spring forces and weight caused by gravity.
Use the formula below for gravity:
w = m · g
Finally, after the above steps, the rope can be simulated but it will never stop. This is be-
cause we have not considered damping yet. Damping represents the energy loss due to
friction and other resistive forces in physical systems. Incorporating damping into simula-
tions makes them more realistic by preventing infinite oscillations and allowing the system
to settle into an equilibrium state over time. In the Euler method, damping is implemented
by subtracting a vector proportional to the velocity from the forces acting on each mass:
Damping force = −damping_factor · velocity
In this task, refer to the above instructions and complete Rope::simulateEuler in rope.cpp ,
including the application of damping. Your implementation should handle IntegrationMethod
method, which determines the integration type to be used.
Execute ./task2_1 to observe the results of the explicit Euler method and ./task2_2
for the semi-implicit Euler method. If your implementation of damping is correct, the rope
should eventually come to a rest in semi-implicit simulations. Adjust the values in config
in task2_1.cpp and task2_2.cpp to see what happens.
Please explain your implementation with the screenshot of your code in your report. By
observing the results of two differentmethods, briefly discuss their differences and reasons.
Task3: Explicit Verlet (30 marks)
Next, your task is to implement the Rope::simulateVerlet method in rope.cpp to sim-
ulate the rope using the Explicit Verlet integration method. Verlet is another method that
solves all constraints. The advantage of this method is that it only deals with the location
of the vertices in the simulation and guarantees fourth-order accuracy. Unlike the Euler
method, the Verlet integral updates the next position in the following way:
xt+1 = xt + (xt − xt−1) + at ·∆t2
Where:
• xt+1 is the position of a node at the next time step.
• xt is the current position of the node.
5
• xt−1 is the position of the node at the previous time step.
• at is the acceleration at the current time step.
• ∆t is the time step.
You should also introduce damping to this method. Damping in the Verlet integration
method is slightly different. Since Verlet integration is based directly on updates to posi-
tion, damping is incorporated by adjusting the position update formula to include a damping
term. This term reduces the change in position from the last step, and the damping coef-
ficient is typically smaller than that used in the Euler method, to match the characteristics
of Verlet integration. The formula for damping in the Verlet method is:
xt+1 = xt + (1− damping_factor) · (xt − xt−1) + at ·∆t2
Run ./task3 , you are expected to observe the rope gradually coming to a stop after
integrating damping into the simulation.
Please explain your implementation with the screenshot of your code in your report.
Task4: Expanding to Cloth (15 marks)
This task extends the simulation concepts from a rope to a cloth. You will work on the
Cloth class in cloth.cpp , where you will need to complete the initializeMasses and
linkSprings functions.
Initialize Masses
The initializeMasses function should calculate the initial positions of the cloth’s nodes
based on the provided center, size, and node count in each dimension (x and z). Each
node represents a mass positioned on a grid that is to be created in the x-z plane. This
grid must be evenly spaced to accurately represent the cloth’s surface.
To initialize the masses effectively:
1. Calculate the step size between nodes in both the x and z directions based on the
number of nodes and the total size of the cloth. The step size in the x-direction can
be calculated as step_x = size.xnum_nodes_x−1 and similarly for the z-direction.
2. For each row (z-direction) i, iterate through each column (x-direction) j to set the po-
sition of a mass. The position for each mass is given by:
position = (top_left.x+ j × step_x, center.y, top_left.z+ i× step_z)
3. Instantiate a new Mass object at each calculated position and store it in the masses .
4. By deafult, all masses are not fixed.
6
Link Springs
The linkSprings function is responsible for connecting the initializedmasseswith springs.
Refer to the diagram in the lecture slides for more details on implementing this function.
The implementation must include three types of springs mentioned:
• Structural Springs: Connect each mass with its immediate horizontal and vertical
neighbors to simulate the basic fabric structure.
• Shear Springs: Link each mass diagonally to neighboring nodes to counteract shear
deformations.
• Flexion Springs: Connect nodes that are two positions apart to simulate the bending
behavior of the cloth.
Figure 1: Lecture Slide
Run ./task4 , you should see the cloth drawn on the screen, but it should remain station-
ary.
Please explain your implementation with the screenshot of your code in your report.
Task5: Verlet Integration with Collision Handling (10 marks)
In this task, implement the simulateVerlet function in cloth.cpp to simulate the cloth
using the Verlet integration method with added collision handling. You can directly copy
the simulateVerlet method from rope.cpp and make the necessary modifications to
include collision handling where appropriate as provided in the code framework. Then,
run ./task5_1 , and you are supposed to observe the cloth swaying and its top left and
7
right corners are pinned.
Next, complete the checkCollision and resolveCollision functions in box.h . For
resolveCollision , use a straightforward approach by simply resetting the mass’s posi-
tion to its last position. This method is not precise, but it is very simple and effective for
preventing the cloth from intersecting in the simulation.
Run ./task5_2 , and you are supposed to observe the cloth descending from above and
settling on the box.
Please explain your implementation with the screenshot of your code in your report.
Possible additional penalties:
• Failed to remove intermediate files.
• Failed to rename the zip file.
• Uploaded file is corrupted.
• Code cannot be successfully compiled.
• Late submission.
• Failed to fill in your information in the declaration of originality.
• Other penalties may apply if failed to follow the instructions.