William
William

Reputation: 8808

How can I find the arctan of a right triangle using only the hypotenuse?

Okay, so I need to make C go the shortest path from A to B. A to B is the hypotenuse of my right triangle, and I need to give C the arctan of said triangle. How do I do this, and does the formula have a name?

Upvotes: 2

Views: 3960

Answers (5)

If you only have one length and there is no hidden assumption here (like say, one side of the triangle has been normalized): you can't.

An interesting hidden assumption might be:

  • All distances are integers
  • The triangle is at least as long as it is tall.

Then the problem is merely hard.


If A and B are points, then the angle you want is presumable the one taken to the x-axis, and you get it by (using the fortranish names):

atan((B.y - A.y)/(B.x - A.x))

or if you have it in your library

atan2((B.y - A.y),(B.x - A.x))

which handles the divide by zero cases neatly...

Upvotes: 1

Mike Dunlavey
Mike Dunlavey

Reputation: 40659

Most systems have Arctan2(dy, dx) which gives you an angle in a full circle (and takes care of verticals), so you would say Arctan2((By - Ay), (Bx - Ax)) to get the direction in radians (counterclockwise from East). For degrees multiply by 360/(2*PI).

Just make sure A != B.

Upvotes: 2

Beska
Beska

Reputation: 12667

It's not clear exactly what you're asking, but I think you're trying to find the angle of the A-B line. I'm going to make the assumption that you know, or can figure out the (x,y) coordinates of both A and B, because otherwise you won't be able to solve the issue.

It sounds like you've outlined the majority of the solution...the angle will be equal to the arctan of the (y/x) distance. So if we consider A(y) to be the y coordinate of A, then you're looking at something like:

arctan ((A(y) - B(y)) / (A(x) - B(x)))

Does that help? Or are you looking for something slightly different?

EDIT: One thing to be aware of is the order in which you consider the terms (whether you're going from A to B or vice versa), etc. You will have to be thoughtful about this or you could end up with some sign problems.

Upvotes: 3

Yes - that Jake.
Yes - that Jake.

Reputation: 17121

If A to B is the hypotenuse of your right triangle, A to B will also be the shortest path from A to B because it is a straight line between the points.

You can calculate the arctangent of either non-right angle by dividing the length of the adjacent side by the length of the opposite side because it's the inverse of the tangent. But, with the information you've described, you will be lacking either the numerator or the denominator.

There are an infinite number of right triangles with a hypotenuse of a given length.

Upvotes: 0

Antti Huima
Antti Huima

Reputation: 25522

Arctan would result in degrees or radians so your A and B most likely have coordinates like (x, y). Then you do arctan((By - Ay) / (Bx - Ax)) if I remember correctly, here Bx is the x coordinate of B etc.

If A and B do not have coordinates, you cannot get degrees out meaningfully.

Upvotes: 1

Related Questions