Results 1 to 6 of 6
 08182008, 06:47 PM #1Member
 Join Date
 Jul 2008
 Posts
 16
 Rep Power
 0
 08182008, 07:35 PM #2
show us your code please,to see closely ,what is the problem
 08182008, 07:57 PM #3
Sounds like you need a trig function. Like sin and cos
You've got the hypotenuse("A") and angle(theta) and need to compute the x and y
It's been a long time.
 08182008, 08:01 PM #4Member
 Join Date
 Jul 2008
 Posts
 16
 Rep Power
 0
I am trying to simulate Random Walk where a mobile node is moving from one point(M,N) to another (X,Y) at a speed v and in time t at an angle "theta". distance = v*t. I need to find out how to find X,Y.
The code I have written so far is :
import java.awt.geom.Point2D;
import java.util.*;
public class RandomWalk
{
Point2D from;
double direction;
int speed = 10; // 10m/s already defined in Wei's paper
double time;
Point2D destination;
RandomNumberGenerator generator = new RandomNumberGenerator();
Vector angles = new Vector();
public void getRandom() // randomly calculate an angle in radians and convert to angle
{
for(int i=0;i<1000;i++)
{
double angle = Math.toDegrees(generator.irand(0,360));
angles.addElement(angle);
}
}
public void getdestinationCoord(Point2D ptd)
{
// (r*cos(phi), r*sin(phi))
}
public double distance(Point2D pt) {
return destination.distance(pt);
}
public void setLocation(Point2D p) {
destination.setLocation(p);
}
public RandomWalk(Point2D from, double direction, int speed, double time)
{
super();
this.from = from;
this.direction = direction;
this.speed = speed;
this.time = time;
}
public double distanceSq(Point2D pt)
{
return from.distanceSq(pt);
}
public String toString()
{
return from.toString();
}
}
 08182008, 10:47 PM #5Java Code:
import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class TrigTest extends JPanel { Point2D.Double center = new Point2D.Double(200, 175); protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.blue); g2.fill(new Ellipse2D.Double(center.x2, center.y2, 4, 4)); g2.setPaint(Color.green.darker()); Point2D.Double p = getPoint(45.0, 200.0); g2.fill(new Ellipse2D.Double(p.x2, p.y2, 4, 4)); g2.setPaint(Color.red); p = getPoint(60.0, 150.0); g2.fill(new Ellipse2D.Double(p.x2, p.y2, 4, 4)); } private Point2D.Double getPoint(double angle, double distance) { // Angles in java are measured clockwise from 3 o'clock. double theta = Math.toRadians(angle); Point2D.Double p = new Point2D.Double(); p.x = center.x + distance*Math.cos(theta); p.y = center.y + distance*Math.sin(theta); return p; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new TrigTest()); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } }
 08182008, 11:24 PM #6Member
 Join Date
 Jul 2008
 Posts
 16
 Rep Power
 0
Similar Threads

Nodes and edges..making visible and invisible based on distance
By sfaiz in forum Java AppletsReplies: 2Last Post: 04142009, 11:01 PM 
Project TuiVox: Empowering distance learning, charities and social networking.
By Az.Sanders in forum Advanced JavaReplies: 0Last Post: 07272008, 08:56 PM 
just starting
By specbailey in forum New To JavaReplies: 23Last Post: 08142007, 12:25 AM 
Calculate Tax in java
By toby in forum New To JavaReplies: 2Last Post: 07302007, 10:03 AM 
Calculate what e1 and e2 should be
By Legoland in forum New To JavaReplies: 11Last Post: 07022007, 07:01 PM
Bookmarks