Giter VIP home page Giter VIP logo

clothsim's Introduction

Simple 2D cloth simulation made as a final project for Introduction to Java class. Build in NetBeans.

Implementation

The application is written in java and using only inherent java libraries. Implementation wise there were a few technical difficulties which sadly set me back quite a lot and I was not able to deliver it when planned. One big problem is the translation between physics calculation which most are in double values, and pixels on the screen which are strictly integers. Also my first design was to use acceleration based physics for the elasticity of the cloth but that proved to be very inefficient and inaccurate (the calculations of arctan() and cos() are estimates not exact values).

The final design came to be based on three main classes + one renderer and two main algorithms. Each passes objects between each other and no global variables are declared.

The base class is Particle which defines the basic unit in a particle simulation, it contains the position in timestep = x and in timestep = x - 1 (current position and past position) it also holds the variables of acceleration and whether the particle can be moved or its static. Its main method only solves the Verlet Integration for a given elapsed time (dT).

The links between the particles are defined in the class Constraint. It holds the starting particle and the ending particle of a constraint and the rest length between them. Its methods deal with keeping the connected particles at a certain distance from each other (Distance Correction) and finding the distance between them using basic linear algebra.

The most important class is the Cloth. It has two main elements the matrix of particles and the ArrayList of the constraints between them. It initializes the particles based on a starting position using a standard nested loop and does the same with the constraints except here uses a grid traversal approach (right, bottom). The update function loops through all the constraints “solving” them and then applies to all points the verlet integration. To have a better representation of momentum of the points all constraints generally should be solved several times within the same frame to “relax” them.

Verlet Integration http://lonesock.net/article/verlet.html

clothsim's People

Contributors

jozigila avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.