Iam doing a java swing application. In that i need to get points along the line. Can you please help me with this?
Please help me
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Iam doing a java swing application. In that i need to get points along the line. Can you please help me with this?
Please help me
I have the following code with me. But sometimes it won't give me correct points
public static Point[] PointsAlongLine(Point start, Point end, int spacing) {
int xDifference = end.x - start.x;
int yDifference = end.y - start.y;
int absoluteXdifference = Math.abs(start.x - end.x);
int absoluteYdifference = Math.abs(start.y - end.y);
int lineLength = (int)Math.sqrt((Math.pow(absoluteXdifference, 2) + Math.pow(absoluteYdifference, 2))); //pythagoras
int steps = lineLength / spacing;
int xStep = xDifference / steps;
int yStep = yDifference / steps;
Point[] result = new Point[steps+1];
for (int i = 0; i < steps; i++) {
int x = start.x + (xStep * i);
int y = start.y + (yStep * i);
result[i] = new Point(x, y);
}
result[steps]=end;
return result;
}
Can you post the results of the program and explain what is wrong with them and show what the results should be?
If you don't understand my answer, don't ignore it, ask a question.