# NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

## Easy Java Simulations (2001- ) => Collaborative Community of EJS => Topic started by: lookang on March 01, 2009, 12:04:14 am

 Title: Ejs Open source java applet Resolving a Vector in 2 perpendicular directions Post by: lookang on March 01, 2009, 12:04:14 am Resolving a Vector in 2 perpendicular directions by lookang original source code by hwang fu-kwun, remixed for helping visualization of components reference:http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=634.msg2195#msg2195http://www.walter-fendt.de/ph14e/forceresol.htm Title: Re: Resolving a Vector in 2 perpendicular directions Post by: lookang on March 02, 2009, 06:00:50 am more1. added centre of (x,y) to make drawable visible2. used actual length instead of unit length  xp=x+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.cos(Math.atan2(dy1,dx1)); // xp = x + component cta1yp=y+Math.sqrt(dx2*dx2+dy2*dy2)*Math.cos(Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))*Math.sin(Math.atan2(dy1,dx1)); // 3. added Rcos = R*Math.cos((Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1)));Rsin = R*Math.cos((Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1)));4. change the logic of drawing the angle polyon todc = (Math.atan2(dy2,dx2)-Math.atan2(dy1,dx1))/(n-2);// modify to draw from black line sing dx and dy as inputspx=x; // for drawing angle polygonpy=y; //for(int i=1;i  c=Math.atan2(dy2,dx2)-(i-1)*dc;  // modify to work drawing from black line//  if(c<-pi)c+=2*pi; // no necessary   px=x+d*Math.cos(c); //   py=y+d*Math.sin(c); //}5. added functions to make slider draggable to control the graphics, thanks Prof Hwang!