Entry 4532

processing script

   

Submitted by anonymous on May 24, 2010 at 7:49 p.m.
Language: Java. Code size: 3.1 KB.

MyPoint punt3 = new MyPoint ();
MyPoint punt1 = new MyPoint ();
MyPoint punt2 = new MyPoint ();

PVector pesDir; 
float pes = 50;

MyVector pesVec, v1, v2;

float mouseXtemp = 250; //posició inicial del punt que penja
float mouseYtemp = 200;

void setup () {
  size (500, 300);
  smooth();
}

void draw () {
  background(150);
  punt3.byCartesianCoordinates (mouseXtemp, mouseYtemp);
  punt1.byCartesianCoordinates (100, 100);
  punt2.byCartesianCoordinates (400, 100);
  punt3.display();
  punt1.display();
  punt2.display();

  pesDir = new PVector (0, pes);
  pesVec  = new MyVector ();
  pesVec.byPointDirection (punt3, pesDir);
  pesVec.display();

  //CALCUL////////////////////////////////////////////////////////////////////////////////////////////
  // La suma de forces pel punt 1 ha de ser igual a 0. 
  // Utilitzem el mètode de Cramer per resoldre aquest senzill sistema d'equacions 
  // v1 = sistemaEq.x (v1Dir);
  // v2 = sistemaEq.y (v2Dir);
  // sistemaEq.x (v1Dir) + sistemaEq.y (v2Dir) = pesDir

  PVector v1Dir = new PVector (punt1.x-punt3.x, punt1.y-punt3.y); //vector de la corda 1
  PVector v2Dir = new PVector (punt2.x-punt3.x, punt2.y-punt3.y);
  
  CramersRule sistemaEq = new CramersRule ();
  sistemaEq.twoByTwo (v1Dir.x, v2Dir.x, v1Dir.y, v2Dir.y, -pesDir.x, -pesDir.y);
  
  //PRIMER_VECTOR////////////////////////////////////////////////////////////////////////////////////
  
  PVector v1Reaccio = new PVector (sistemaEq.x*v1Dir.x, sistemaEq.x*v1Dir.y);
  
  v1 = new MyVector ();
  v1.byPointDirection (punt1, v1Reaccio);
  stroke (255,0,0);
  v1.display();
  stroke (0);
  v1.decompose();
  
  //SEGON_VECTOR////////////////////////////////////////////////////////////////////////////////////
  
  PVector v2Reaccio = new PVector (sistemaEq.y*v2Dir.x, sistemaEq.y*v2Dir.y);
  
  v2 = new MyVector ();
  v2.byPointDirection (punt2, v2Reaccio);
  stroke (0,255,0);
  v2.display();
  stroke (0);
  v2.decompose();
  

  ////////////////////////////////////////////////////////////////////////////////////////////////////
  stroke (0);
  MyLine linea1 = new MyLine ();
  linea1.byPoints (punt3, punt1);
  strokeWeight (v1.vecLength/10);
  stroke (0, 80);
  linea1.display();

  MyLine linea2 = new MyLine ();
  linea2.byPoints (punt3, punt2);
  stroke (0, 80);
  strokeWeight (v2.vecLength/10);
  linea2.display();

  ///Dibuixem el polígon tancat per comprovar l'equilibri de forces
stroke (0);
  strokeWeight (0);
  MyPoint pBase = new MyPoint ();
  pBase.byCartesianCoordinates (400,200);
  MyVector pesVecPol = new MyVector ();
  pesVecPol.byPointDirection (pBase, pesDir);
  MyVector v1Pol = new MyVector ();
  v1Pol.byPointDirection (pesVecPol.endPoint, v1Reaccio);
  MyVector v2Pol = new MyVector ();
  v2Pol.byPointDirection (v1Pol.endPoint, v2Reaccio);
  pBase.display();
  pesVecPol.display();
  stroke (255,0,0);
  v1Pol.display();
  stroke (0,255,0);
  v2Pol.display();
  stroke (0);

}

void mouseDragged () {
  if (mouseY > 100){
    mouseXtemp = mouseX;
    mouseYtemp = mouseY;
  }
}  

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).