Geez this is even better than I expected. I was worried with negative values hence the Math.abs and I wasn't sure how to express in degrees.

Thank you very much for your answers guys, the atan2 is completely new to me ;)

Thanks again

On Sep 15, 2010, at 5:50 PM, Kostya Vasilyev wrote:

Um, no.

Math.atan2 takes two values, not one.

Math.atan2(y2 - y1, x2 - x1)

This gives correct result even for x2 and x1 being very close to each other. Depending on the sign of y2 - y1 that's either "up" or "down".

-- Kostya

15.09.2010 20:45, Robert Green пишет:
Kostya hit it:

float angleDegrees = Math.toDegrees(Math.atan2((y1 - y2) / (x1 -
x2)));

On Sep 15, 11:32 am, Kostya Vasilyev<[email protected]>  wrote:
  Pedro,

Java (and pretty much any language's) trig functions work with angles
expressed in radians.

http://en.wikipedia.org/wiki/Radian

To convert to degrees, multiply by 180 / 3,1415926.... (in Java, that's
Math.PI). Or just call Math.toDegrees.

Better yet - use Math.atan2 ( difference along Y, different along X). This one correctly handles the case of value3-value4 being zero (or very
close thereof).

-- Kostya

15.09.2010 20:22, Pedro Teixeira пишет:

Hi,
I'm having problems with JAva and trigonometry to calculate a
direction from a point to a certain point...
I want to translate this equation to Java-wise:
tg^-1 = |value1-value2| / |value3-value4|
And I'd like the result in degrees.. how can I do this? any ideia?
--
Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Pedro Teixeira

www.pedroteixeira.org

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to