## 3 Method
### Position-Based Dynamics Progression  
Algorithm 1 shows the flow of cloth simulation using the Unity version of the PBD algorithm implemented in this study as a pseudocode:  
```
1:Initialize cloth mesh, rest positions, and parameters
2:For each time step:
3: PredictPositions()
4: // PBD core loop
5:For iteration = 1 to solverIterations:
6: SolveDistanceConstraints()
7: SolveBendingConstraints()
8: UpdateVelocitiesAndPositions()
9: HandleExternalCollisions()
10: HandleSelfCollisions()
11:FunctionPredictPositions():
12:For each vertex v:
13:If v is not pinned:
14: v.predictedPosition = v.position + timeStep * v.velocity + gravity * timeStep^2 / 2
15:FunctionSolveDistanceConstraints():
16: For each edge (v1, v2):
17: restLength = initialLength(v1, v2)
18: currentVector = v2.predictedPosition - v1.predictedPosition
19: currentLength = length(currentVector)
20: correction = (currentLength - restLength) * currentVector / currentLength
21: If v1 is not pinned:
22: v1.predictedPosition += 0.5 * stiffness * correction
23: If v2 is not pinned:
24: v2.predictedPosition = 0.5 * stiffness * correction
25:FunctionSolveBendingConstraints():
26:For each triangle pair (t1, t2):
27: Calculate dihedral angle
28: Calculate bending force
29: Apply force to vertices of t1 and t2
30:FunctionUpdateVelocitiesAndPositions():
31:For each vertex v:
32:If v is not pinned:
33: v.velocity = (v.predictedPosition - v.position) / timeStep
34: v.velocity *= (1 - damping)
35: v.position = v.predictedPosition
36:FunctionHandleExternalCollisions():
37:For each vertex v:
38:If v collides with external object
39: Move v to collision surface
40: Update v.velocity (reflect or absorb)
41:FunctionHandleSelfCollisions():
42:For each vertex pair (v1, v2):
43:If distance(v1, v2) < collisionThreshold:
44: Separate v1 and v2
45: Update velocities of v1 and v2 The algorithm begins by representing the cloth as a mesh structure that is composed of interconnected vertices. Each vertex holds position and velocity data, and is linked to neighboring vertices, establishing the structural integrity of the cloth. Each simulation step consists of the following sequential processes:

1. Prediction of Vertex Positions: The algorithm first predicts the subsequent position of each vertex by factoring in its current position, velocity, and gravitational forces. This prediction accounts for the time step, ensuring that pinned vertices remain fixed. 2. Constraint Resolution: Physical constraints on the cloth are resolved through multiple iterations. The two primary constraints are the distance constraint and the bending constraint. The distance constraint prevents overstretching or compression by maintaining the original distance between connected vertices, with the stiffness parameter controlling the cloth's stretch and crumple response. The bending constraint, which manages the extent of bending, is addressed by calculating the angle between adjacent triangles. 3. Velocity and Position Update: The new velocity and position of each vertex are then updated based on the predicted positions. A damping parameter is applied in this stage to simulate kinetic energy loss, allowing for the cloth to naturally come to rest, rather than moving indefinitely. 4. Collision Handling: Two types of collisions are managed: external collisions (between the cloth and another object) and self-collisions (within the cloth itself). For external collisions, the impacted vertex is repositioned on the collision surface, and its velocity is appropriately adjusted. For self-collisions, when different parts of the cloth come too close, the collision is detected, and the vertices are separated accordingly. These stages ensure realistic cloth behavior, balancing physical accuracy and computational efficiency for real-time simulation applications. ### Vertex Block Descent Progression

Algorithm 2 shows the flow of cloth simulation using the Unity version of the VBD algorithm implemented in this study as a pseudocode.