Sign in to follow this  
sporedude

Help with Triangle

Recommended Posts

hi all I wanted help with the following. I have a triangle in 3D with coordinates of 2 of its vertices given. I am also given the length of the 3 sides of the triangle. Now I need to find the coordinates of the 3rd vertex. Now this might just be elementary geometry but i would appreciate if someone could help me with it. SD

Share this post


Link to post
Share on other sites
oh yeah.... i got that.... there can be infinite no. of triangles with the 3rd vertex leading to formation of a circle.

what if i assume that all the 3 vertices of the triangle are in the same plane. then i guess there would be 2 possible traingles. how would i find the 3rd vertex then?

cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by sporedude
oh yeah.... i got that.... there can be infinite no. of triangles with the 3rd vertex leading to formation of a circle.

what if i assume that all the 3 vertices of the triangle are in the same plane. then i guess there would be 2 possible traingles. how would i find the 3rd vertex then?

cheers


All three vertices have to be on the same plane if they form a triangle. Think of the two vertices as forming a hinge. For example, hold a pen between your thumb and index finger. Imagine a triangular paper flag extending from the pen. Hold your hand in the same place and swivel the paper triangle flag around the pen.

You can find the range of all possible triangles, but there are an infinite number of them.

What you may want to do is convert this problem into 2D and understand how it works. In 2D there are only two solutions.

Share this post


Link to post
Share on other sites
Here is an example of finding one of the possible vertices of a 2D triangle, given vertex(3,3), vertex(7,7), and lengths:
(between (3,3) and (?,?): length 4
(between (7,7) and (?,?): length 4
(between (3,3) and (7,7): length 5.657 (actually we could calculate this ourselves too).




Basically, what we did was use the cosine rule to calculate the angles between the vectors. Then we used these angles to calculate a unit vector representing the third unknown vector. We then scaled this unit vector by the length of the known side and then translated it into the correct position to get the exact coordinates.

Let me know if you have any questions. There are also optimized ways of doing this.

[Edited by - jdaniel on May 16, 2006 10:24:54 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by jdaniel
All three vertices have to be on the same plane if they form a triangle.


In fact, 3 points always belong to a same plane, which is unique if the 3 points are different, or which can be an infinite number of plane if at least 2 points are identical.

To me your sentence sound as if one could find 3 points for which there would be no plane that would contain all three of them. It would be as if in 2D geometry there could be "two non-aligned points"

Just wanted to clear that up for non-geometry-friendly folks out there.

Quote:
In 3D? There are an infinite number of triangles that can be created with only that information.


In fact, there could be an infinity of solutions (without going into the math details, that would be true if the two other edge length would be "large enough") or exacly one solution (if the two edges are "just the right length") or no solution at all (if the two edges are "too short")

But this is easier to understand when thinking of a 2D space (for which this problem's solution could be either: two triangles, one triangle or no triangle at all)

--------------------------

Say (x,y) is what you're looking for.

(1) - Then ,distance-to-the-point(3,3)=4 condition:

(x-3)*(x-3) + (y-3)*(y-3) = 4 * 4
<=> x^2 - 6x + 9 + y^2 - 6y + 9 = 16

(2) - Also ,distance-to-the-point(7,7)=4 condition:
(x-7)*(x-7) + (y-7)*(y-7) = 4 * 4
<=> x^2 - 14x + 49 + y^2 - 14y + 49 = 16

Frow what you can get (1) - (2):
8x - 40 + 8y - 40 = 0 <=> x + y = 10 <=> y = 10 - x

Feed that into (1) and you'll get that:
x^2 - 6x + 9 + (10 - x)^2 - 6(10-x) + 9 = 16

Which you can easily simplify to a simple 2nd degree polynom, which you can solve with REAL values (finding complex solution would have no point, well, I think, for a trival application at least)

- If there are two solutions, then it means the circles intersect at two different locations, which means there are two trianglees that fit.

- If there is only one solution, it means that the circles are tangential and intersect only at a single location

- If there are no solution at all, it means that the circles do not intersect with each other.

(So, that demonstrates what I said before: 2, 1 or 0 solution)

The same method could be extended to a 3D world, in which the known distances from each known vertex would describe two spheres, and their intersection would be a circle, a point or nothing at all.

I hope I could give you another perpective for solving this problem.
Sorry that my native language is not english so my mathematical vocabulary might not be perfect, while understandable (I hope :p)

Janta

Share this post


Link to post
Share on other sites
Quote:
Original post by sporedude

what if i assume that all the 3 vertices of the triangle are in the same plane.


What if you don't ? :D ;-)

Well, if you don't, then you just reinvented the euclidian geometry (or some stuff like that since I'm no math expert though :p)

What I just mean is that 3 vertices in a 3D space have no choice but to be in the same triangle/plane.

Share this post


Link to post
Share on other sites
thanks janta and jdaniel. you insights were really helpful.

daniel thanks for pointing out the Cosine rule mate... that could actually do the trick for me. i will keep posted if i have trouble implementing it.

janta ... thanks for your rather deep insight. I haven't read your post closely but from what i can make out, u seem to be a perfect 'geometrician'.

Thanks for poiting the basic flaw in my assumption. I agree that 3 points in 3D space have to be only a plane... they have no choice. guess i was confused with the possibility of there being inifite no. of solutions. thanks for pointing it out.

cheers

Share this post


Link to post
Share on other sites
janta i liked u method of finding the polynomial and then solving it too, as it tend to cover all the conditions (2, 1, and 0). I would try implementing that too.. thanks a lot

cheers

Share this post


Link to post
Share on other sites
hey jdaniel

now in the example u gave, u can find the unit vector using cosine and sine. what if none of the angles is not a perfect multiple of 90 degrees. how would i find the unit vecotr then

cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by sporedude
janta i liked u method of finding the polynomial and then solving it too, as it tend to cover all the conditions (2, 1, and 0). I would try implementing that too.. thanks a lot

cheers


In fact jdaniel's points the same thing out if you look more closely, but he hasn't emphasized on that particuler point.

With his method, you can stop the calculations after you've found the value of the first angle, since this is just enough to build a complete triangle at a particular location in space (2 points position, 3 length and 1 angle)

Now if you take a look at his solution, it yields to something like:

x = cos(A) with x being a known value.
How this equation can be solved all depends on the value of x.

- If x is in the interval ] -1.0f ; 1.0f [

Then there are TWO solution: A = arccos(x) or A = - arccos(x)
Physically that leads to two possible triangles symmetrical with each other



- If x = -1.0f or if x = 1.0f

Then there is a single solution which is either A = 0 or A = 180 (degrees)
Physically, If you have some ability to visualize things in space/plane, you'll understand that the triangle you've just determined is a 'flat' triangle (or degenerated in GPU words). This is just perfectly logical since we are in the case where the length provided are just fitted to make a triangle. I other words we have a + b = c or something similar

Indeed, x = (b² + c² - a²)/(2bc)
So if x = 1 then
2bc = b² + c² - a²
a² = b² - 2bc + c²
a² = (b - c)²
a = b - c
or a = c - b


- If x is either < -1.0f or > 1.0f

Then there is just no solution at all since there are no A such as cos(A) > 1.0
(and in this case arccos(x) is not defined and cannot be calculated)

Share this post


Link to post
Share on other sites
Quote:
Original post by sporedude
hey jdaniel

now in the example u gave, u can find the unit vector using cosine and sine. what if none of the angles is not a perfect multiple of 90 degrees. how would i find the unit vecotr then

cheers


Basically, we determine the angles within the original triangle as I demonstrated above. Now the problem you encounter is this: In the first example it is clear that you use 270 degrees to feed the cosine/sine functions. But two of the triangle's edges were parallel to the cartesian axes. What if no edge of the triangle was parallel to an axis? How would the cosine/sine be fed?

It turns out, we can just create a new triangle for ourselves to figure it out. Look at this illustration. Your triangle in 2D space is blue.

description of your image

There are two new triangles in pink. Look at the pink triangle to the left of the blue triangle. We just created this one ourselves. Notice that one of the angles of the new triangle is 90 degrees. Also note that we know the lengths of all sides and we know the cartesian coordinates of every point.

Look at the angles between the blue and pink triangle. I labled the pink angle 'a' and the blue angle 'b'. It should be apparent now that we can use the cosine rule to find angle 'a' and to find angle 'b'.

Now you can feed the cosine and sine functions as we did in the first example.

NOTE: I show two triangles in that diagram. That is because the unknown point in the blue triangle could be the (1,5) coordinate instead of the one with the question mark. In this case, we would use the pink triangle to the right.

And in regards to your original question regarding a triangle in 3D space, this same method could be used. You just have to do it in 2D twice. Think about that above diagram as looking directly down the z-axis. You could also think about it as looking directly down at the y axis. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this