I need a method that returns the degree's needed for a rotation for one image to basically turn to the other image,
example:
The degrees the the the rectangle, will need to turn to the dot on the circle,
I hope you get what I mean,
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.
I need a method that returns the degree's needed for a rotation for one image to basically turn to the other image,
example:
The degrees the the the rectangle, will need to turn to the dot on the circle,
I hope you get what I mean,
If I do understand what you mean, you need to use some simple trig to retrieve the angle...
sin(angle) = opposite/hypotenuse
or
angle = arcsin(opposite/hypotenuse)
Here, angle would be between the vertical arrow and the line between circle and rect, opposite would be the x distance between circle and rect, and hypotenuse would be distance bewtween circle and rect.
Time (May 13th, 2010)
Have a look at Trigonometry Calculator - Visual Triangle Math Calculator
That might give you a visual clue as well as the formulas.
// Json
You're formula is slightly flawed. Arctangent is picky and doesn't take into account the signs of the two values, or when the x-direction is very close to zero (you'll essentially be trying to divide by 0, a very bad prospect).
You can cheat a little bit by using the atan2 method to get the angle back from an x,y distances between the two points (in vector notation, going from the rectangle point directed towards the circle's point this is just x=circle.x - rectangle.x, y= circle.y - rectangle.y).
System.out.println("The angle from the positive x-axis is: " + Math.atan2(yDistance, xDistance));
Time (May 13th, 2010)
I was wondering why the occurrence of that was happening,
Well thanks that fixed one issue,
Another issue I'm having is the instance of 2 or more,
Once I use make one object(1) face another object(2), If i send another object(3) face object(2) he ends up facing object(1)
without looking at the code there's no way we can tell what's going wrong. I'm guessing that you're either passing the wrong object references, though.