Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2008, 04:16 PM
Member
 
Join Date: Apr 2008
Location: Cornwall, UK
Posts: 10
dazza-s is on a distinguished road
Pulley Simulation..HELP
Hi

I am trying to simulate a line being effected by a pulley.

At the moment this is very simple. I have 3 plotted points. 1 The begining point, 2 the pully and 3 the end point. A line is drawn to each point so point 1 to point 2, point 2 to point 3.

I want to say if I move point 1 down then point 2 will stay static but point 3 will move up to point 2 by the equal amount of travel applied to point 1. Can do this easily just on the x axis but when I start mixing in the y axis as well I can't figure out how to plot the new position of point 3. I am guessing I would have to use triganomatry (sp?)

Please help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-18-2008, 04:47 PM
Member
 
Join Date: Apr 2008
Location: Cornwall, UK
Posts: 10
dazza-s is on a distinguished road
It's ok, I have figured it. I just use the x position of the pully and decrease the x position of point 3 whilst doing the same to the y until the x position of 3 is equal to that of the pully. The nearer I get to the pully the more x I decrease. I would like some help later as I will be applying forces and pressures to the pulley system so would like the pulleys to act in different ways. I.e The pulley could be attached to a weight and the top of the pulley connected to a tow point via a elastic chord. So the pulley would move somewhat until the elastic overcomes the weight.

Actually any thoughts and tips would be good
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-18-2008, 11:51 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; public class PulleyTest extends JPanel implements ChangeListener { PulleyModel model = new PulleyModel(200,50,40,400); Rectangle weight = new Rectangle(65, 40); int bitterEndHeight = 100; public void stateChanged(ChangeEvent e) { bitterEndHeight = ((JSlider)e.getSource()).getValue(); repaint(); } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // draw pulley g2.setPaint(Color.blue); int dia = model.diameter; Point p = model.loc; double x = p.x - dia/2; double y = p.y - dia/2; Ellipse2D.Double pulley = new Ellipse2D.Double(x, y, dia, dia); g2.draw(pulley); // mark center g2.setPaint(Color.orange); g2.fill(new Ellipse2D.Double(p.x-2, p.y-2, 4, 4)); // int h = getHeight(); int bitterLength = h - bitterEndHeight - p.y; double loadLength = model.getLoadLength(bitterLength); //System.out.printf("bitterLength = %d loadLength = %.1f%n", // bitterLength, loadLength); // check calculations double totalLength = bitterLength + Math.PI*dia/2 + loadLength; //System.out.printf("totalHeight = %.1f%n", totalLength); // locate and draw weight weight.setLocation(p.x+dia/2-weight.width/2, (int)(p.y+loadLength)); g2.setPaint(Color.green.darker()); g2.draw(weight); // draw line g2.setPaint(Color.black); x = p.x-dia/2; g2.draw(new Line2D.Double(x, p.y, x, p.y+bitterLength)); x = p.x+dia/2; g2.draw(new Line2D.Double(x, p.y, x, p.y+loadLength)); } private JSlider getSlider() { JSlider slider = new JSlider(JSlider.VERTICAL, 10, 280, bitterEndHeight); slider.addChangeListener(this); return slider; } public static void main(String[] args) { PulleyTest test = new PulleyTest(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(test); f.add(test.getSlider(), "After"); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } } class PulleyModel { int diameter; Point loc; int lineLength; PulleyModel(int x, int y, int dia, int line) { loc = new Point(x, y); diameter = dia; lineLength = line; } public double getLoadLength(int bitterLength) { // loadLength = lineLength - bitterLength - circumference/2 return lineLength - bitterLength - Math.PI*diameter/2; } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small tennis simulation in Java diego New To Java 1 12-02-2007 02:32 AM


All times are GMT +3. The time now is 04:22 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org