[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model/plugin PhysicsParticle.java, 1.1, 1
Status: Pre-Alpha
Brought to you by:
henryml
From: Sebastian G. <sg...@us...> - 2011-05-09 10:23:00
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/plugin In directory vz-cvs-2.sog:/tmp/cvs-serv24100/src/net/sourceforge/bprocessor/model/plugin Modified Files: PhysicsParticle.java PhysicsNet.java PhysicsSurface.java PhysicsPackage.java Log Message: Physics Surface Solid calculation Index: PhysicsParticle.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/plugin/PhysicsParticle.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PhysicsParticle.java 26 Apr 2011 06:23:02 -0000 1.1 --- PhysicsParticle.java 9 May 2011 10:22:58 -0000 1.2 *************** *** 13,17 **** double m; //mass Vertex f; //force acting on particle ! boolean fix; //fix or movable particle? int ID; //Particle ID for identification Vertex aForce; //additional force - sum of other calculations. Is added to acceleration calculation. --- 13,17 ---- double m; //mass Vertex f; //force acting on particle ! boolean fix; //fix or movable particle? int ID; //Particle ID for identification Vertex aForce; //additional force - sum of other calculations. Is added to acceleration calculation. *************** *** 21,30 **** //constructor ! PhysicsParticle (Vertex node, Vertex velocity, Vertex acceleration, double mass, boolean fixed, int ID) { pos = node; vel = velocity; a = acceleration; m = mass; ! fix = fixed; nPos = new Vertex(pos.getX(),pos.getY(),pos.getZ()); this.ID = ID; --- 21,30 ---- //constructor ! PhysicsParticle (Vertex node, Vertex velocity, Vertex acceleration, double mass, int ID) { pos = node; vel = velocity; a = acceleration; m = mass; ! fix = node.isCorner(); nPos = new Vertex(pos.getX(),pos.getY(),pos.getZ()); this.ID = ID; *************** *** 71,75 **** //move particle void move(double time, double gravity, double particle_drag) { ! if (fix != true) { nPos = new Vertex(pos.getX(),pos.getY(),pos.getZ()); //calculate acceleration --- 71,75 ---- //move particle void move(double time, double gravity, double particle_drag) { ! if ((fix == false) && (pos.isCorner() != true)) { nPos = new Vertex(pos.getX(),pos.getY(),pos.getZ()); //calculate acceleration Index: PhysicsPackage.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/plugin/PhysicsPackage.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PhysicsPackage.java 5 May 2011 16:34:02 -0000 1.3 --- PhysicsPackage.java 9 May 2011 10:22:58 -0000 1.4 *************** *** 12,23 **** /* * To Do ! * 1. Modify new net while simulation is running, i.e. corner property, etc. ! * 2. Change to original net -> changes new net ! * 3. Parameters, toggles and sliders ! * 4. Planarity and regularity of panels, add bending stiffness! ! * 5. Add parameters to b-net and save them! ! * 6. Subdivision ! * 7. Selection => parameter changes to vertices and edges, not only global ! * */ --- 12,30 ---- /* * To Do ! * Michael: ! * parameters additional parameters should be saved when added, change function , the display of the value is not automatically updated. ! * Plugin Parameters and Selection Parameters: they should not be displayed in the same panel. Rather split the existing panel. So there can be a selection and a tool running at the same time and all information is visible. ! * Sliders, Checkboxes, etc. for the plugin controls ! * A plugin button should be able to run a tool with a selection / mouse interaction. ! * ! * Modify new net while simulation is running, i.e. corner property, etc. ! * Planarity and regularity of panels, add bending stiffness! ! * Rectangularity needs improvement, bending stiffness! ! * Add parameters to b-net and save them! - see above, Michael, add and save parameters to original net ! * Subdivision ! * Selection => parameter changes to vertices and edges, not only global ! * Volume calculation and inflation force ! * Auto-detect corners of net (vertices that are only connected to 2 edges) ! * time settings and parameters */ *************** *** 25,31 **** public static class Springsystem extends NetCommand { ! Space union; ! PhysicsNet pN; //physical Net ! Space cNet; HashMap<Edge, Edge> edges = new HashMap(); --- 32,38 ---- public static class Springsystem extends NetCommand { ! Space union; //Union containing Objects created by script ! Space cNet; //copy of b-Net, graphical representation of Physics Net ! PhysicsNet pN; //Physics Net = Simulation Object HashMap<Edge, Edge> edges = new HashMap(); *************** *** 45,49 **** double planeConstant; double planeDamping; ! double normalForce; //boolean editNet; --- 52,57 ---- double planeConstant; double planeDamping; ! //double normalForce; ! double volume; //boolean editNet; *************** *** 75,84 **** planeDamping = 2.0; parameters.put("Planarity Spring Damping [N sec/m]", planeDamping); ! normalForce = 0.0; ! parameters.put("Normal Surface Force [N]", normalForce); //editNet = true; //parameters.putBoolean("Edit B-Net", editNet); - super.initializeNoItem(net); //create copy of b-Net --- 83,93 ---- planeDamping = 2.0; parameters.put("Planarity Spring Damping [N sec/m]", planeDamping); ! //normalForce = 0.0; ! //parameters.put("Normal Surface Force [N]", normalForce); ! volume = 1.0; ! parameters.put("Volume [m3]", volume); //editNet = true; //parameters.putBoolean("Edit B-Net", editNet); super.initializeNoItem(net); //create copy of b-Net *************** *** 86,89 **** --- 95,99 ---- //map = net.getOwnParameters(); cNet = net.copy(map); + cNet.setName(net.getName()+"- Physics Net"); //cNet.edit(); //copy corner points *************** *** 154,160 **** planeDamping = (Double) parameters.get("Planarity Spring Damping [N sec/m]"); //normal Force ! normalForce = (Double) parameters.get("Normal Surface Force [N]"); //boolean parameters //editNet = (Boolean) parameters.getBoolean("Edit B-Net"); ///////////////////////////////////////////////////////////////////////////////////////////// //track changes of bNet and modify Physics Net accordingly --- 164,172 ---- planeDamping = (Double) parameters.get("Planarity Spring Damping [N sec/m]"); //normal Force ! //normalForce = (Double) parameters.get("Normal Surface Force [N]"); //boolean parameters //editNet = (Boolean) parameters.getBoolean("Edit B-Net"); + //Desired Volume + volume = (Double) parameters.get("Volume [m3]"); ///////////////////////////////////////////////////////////////////////////////////////////// //track changes of bNet and modify Physics Net accordingly *************** *** 176,180 **** } - //add a union space containing all new elements union = (Space) net.getOwner().find("PhysicsSystem"); --- 188,191 ---- *************** *** 197,201 **** cNet.edit(); }*/ ! pN.update(guides, 0.02, equalConstant, equalDamping, rectConstant, rectDamping, planeConstant, planeDamping, normalForce); union.add(cNet); } --- 208,212 ---- cNet.edit(); }*/ ! pN.update(guides, 0.02, equalConstant, equalDamping, rectConstant, rectDamping, planeConstant, planeDamping, volume); union.add(cNet); } Index: PhysicsSurface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/plugin/PhysicsSurface.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PhysicsSurface.java 26 Apr 2011 06:33:58 -0000 1.2 --- PhysicsSurface.java 9 May 2011 10:22:58 -0000 1.3 *************** *** 3,6 **** --- 3,7 ---- import java.util.ArrayList; import java.util.HashMap; + import java.util.List; import java.util.*; *************** *** 83,87 **** Vertex averageNormal() { ! Vertex nV = new Vertex(0,0,0); List<Vertex> vertices = bSurf.getVertices(); double num = vertices.size(); --- 84,91 ---- Vertex averageNormal() { ! return bSurf.normal(); ! /* ! * @Michael: algorithm for Normal seems to be so complicated... why? ! Vertex nV = new Vertex(0,0,0); List<Vertex> vertices = bSurf.getVertices(); double num = vertices.size(); *************** *** 109,112 **** --- 113,139 ---- } return nV; + */ + } + + double calcArea() { + double area = 0.0; + List<Vertex> vertices = bSurf.getVertices(); + double num = vertices.size(); + vertices.add(vertices.get(0)); + List<Vertex> crossProducts = new ArrayList<Vertex>(); + for (int i=0; i<num; i++) { + Vertex p1 = vertices.get(i); + Vertex p2 = vertices.get(i+1); + Vertex cP = p1.cross(p2); + crossProducts.add(cP); + } + Vertex sum = new Vertex(0,0,0); + for (Vertex cP : crossProducts) { + sum = sum.add(cP); + } + double dotP; + dotP = Math.abs(averageNormal().dot(sum)); + area = 0.5 * dotP; + return area; } Index: PhysicsNet.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/plugin/PhysicsNet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PhysicsNet.java 5 May 2011 16:34:02 -0000 1.3 --- PhysicsNet.java 9 May 2011 10:22:58 -0000 1.4 *************** *** 17,20 **** --- 17,21 ---- double spring_d = 0.5; //spring damping double particle_d = 3; //particle damping coefficient of drag + boolean solid = false; HashMap<Vertex,PhysicsParticle> particles = new HashMap(); HashMap<Edge,PhysicsSpring> springs = new HashMap(); *************** *** 22,42 **** //constructor ! PhysicsNet(Space bNet, double gravity, double spring_constant, double spring_damping, double particle_damping, double mass, double restLengthFactor) { Map pMap = new HashMap(); //this.bNet = (Space) bNet.copy(pMap); ! this.cNet = bNet; this.spring_c = spring_constant; this.spring_d = spring_damping; this.particle_d = particle_damping; //create Particles and Springs from Vertices of b-Net ! Collection<Vertex> bVertices = bNet.getVertices(); ! Map<Vertex, List<Edge>> edgeMap = bNet.getEdgeMap(bVertices); int counter = 0; for (Vertex bV : bVertices) { ! particles.put(bV, new PhysicsParticle(bV, new Vertex(0,0,0), new Vertex(0,0,0), mass, bV.isCorner(),counter)); counter++; } //create Springs ! Collection<Edge> bEdges = bNet.getEdges(); for (Edge bE : bEdges) { PhysicsParticle pA = particles.get(bE.getFrom()); --- 23,44 ---- //constructor ! PhysicsNet(Space cNet, double gravity, double spring_constant, double spring_damping, double particle_damping, double mass, double restLengthFactor) { Map pMap = new HashMap(); //this.bNet = (Space) bNet.copy(pMap); ! this.cNet = cNet; this.spring_c = spring_constant; this.spring_d = spring_damping; this.particle_d = particle_damping; + this.solid = isSolid(); //create Particles and Springs from Vertices of b-Net ! Collection<Vertex> bVertices = cNet.getVertices(); ! Map<Vertex, List<Edge>> edgeMap = cNet.getEdgeMap(bVertices); int counter = 0; for (Vertex bV : bVertices) { ! particles.put(bV, new PhysicsParticle(bV, new Vertex(0,0,0), new Vertex(0,0,0), mass, counter)); counter++; } //create Springs ! Collection<Edge> bEdges = cNet.getEdges(); for (Edge bE : bEdges) { PhysicsParticle pA = particles.get(bE.getFrom()); *************** *** 50,54 **** } //create PhysicsSurfaces ! Collection<Surface> bSurfaces = bNet.getSurfaces(); for (Surface bS : bSurfaces) { //create HashMaps for Surface --- 52,56 ---- } //create PhysicsSurfaces ! Collection<Surface> bSurfaces = cNet.getSurfaces(); for (Surface bS : bSurfaces) { //create HashMaps for Surface *************** *** 86,89 **** --- 88,117 ---- } + double saveVolume (Space cNet) { + double volume = 0.0; + if (solid) { + volume = calcVolume(); + ParameterBlock block = cNet.getParameters(); + if (block == null) { + block = new ParameterBlock(); + cNet.setParameters(block); + block.putDouble("Volume", volume); + } + block.changeDouble("Volume", volume); + } + return volume; + } + + void saveArea (Surface s) { + ParameterBlock block = s.getParameters(); + PhysicsSurface pS = surfaces.get(s); + if (block == null) { + block = new ParameterBlock(); + s.setParameters(block); + block.putDouble("Area", pS.calcArea()); + } + block.changeDouble("Area", pS.calcArea()); + } + void updatePos(Vertex cV) { PhysicsParticle pA = particles.get(cV); *************** *** 125,131 **** } ! void update(Space guides, double time, double equalConstant, double equalDamping, double rectConstant, double rectDamping, double planeConstant, double planeDamping, double normalForce) { Iterator it; //calculate surface forces it = surfaces.entrySet().iterator(); while (it.hasNext()) { --- 153,160 ---- } ! void update(Space guides, double time, double equalConstant, double equalDamping, double rectConstant, double rectDamping, double planeConstant, double planeDamping, double volume) { Iterator it; //calculate surface forces + double currentVolume = saveVolume(cNet); it = surfaces.entrySet().iterator(); while (it.hasNext()) { *************** *** 135,139 **** s.quadToRect(guides, time, rectConstant, rectDamping); s.planarize(guides, time, planeConstant, planeDamping); ! s.normalForce(guides, time, normalForce); } //claculate particle movement --- 164,172 ---- s.quadToRect(guides, time, rectConstant, rectDamping); s.planarize(guides, time, planeConstant, planeDamping); ! if (volume>0) { ! double normalForce = s.calcArea()*volume/currentVolume; ! s.normalForce(guides, time, normalForce); ! } ! saveArea((Surface) ee.getKey()); } //claculate particle movement *************** *** 163,165 **** --- 196,229 ---- cNet.update(); } + + //check if c-Net forms a solid. + //each edge is connected to 2 surfaces. + boolean isSolid() { + boolean solid = true; + Collection<Edge> cEdges = cNet.getEdges(); + for (Edge nE : cEdges) { + Set<Surface> cSurfaces = nE.getSurfaces(); + if (cSurfaces.size()<2) solid = false; + } + return solid; + } + + //calculate volume of solid + double calcVolume() { + double v = 0.0; + Iterator it = surfaces.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry ee = (Map.Entry)it.next(); + Surface s = (Surface)ee.getKey(); + PhysicsSurface pS = (PhysicsSurface)ee.getValue(); + List<Vertex> vertices = s.getVertices(); + Vertex p = vertices.get(0); + Vertex n = pS.averageNormal(); + //n.normalize(); + double test = p.dot(n); + v = v + pS.calcArea()* test; + } + v = Math.abs(v)/3; + return v; + } } \ No newline at end of file |