Basic Trig Question

This is a discussion on Basic Trig Question within the Tech Board forums, part of the Community Boards category; Hello, Sorry about this but my trig's been firing blanks lately:- If I know the area of a triangle and ...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262

    Red face Basic Trig Question

    Hello,

    Sorry about this but my trig's been firing blanks lately:-

    If I know the area of a triangle and its internal angles, can I work out the length of its sides?

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    Yes, though it'd kind of be a pain.

    If you have all the angles, you can guess the length of one side and use the law of sines to obtain the remaining sides. Once you have all the sides, you can use Heron's formula to calculate the area. This obviously won't match your specified area, but since area scales according to length squared, you can multiply your guess by the square root of the ratios of the areas, i.e. Lreal = Lguess*sqrt(Areal/Aguess).

    Law of sines - Wikipedia, the free encyclopedia
    Heron's formula - Wikipedia, the free encyclopedia

  3. #3
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    There's probably some way you can rearrange the stuff so that you're solving a system of equations as opposed to guessing, but I think guessing then scaling is pretty fast.

  4. #4
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    Okay yeah, since sin(a)/A = constant and so on, you can replace the sides with A = sin(a)/constant, and then solve for the constant, but you'd be solving a 4th order polynomial.

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    Yeah, I did think about doing it iteratively, but I feel that I would end up doing a thousand calculations coming up with something quite simple.

    How about then, if:-

    Constant area, as before;
    I had the ratio of the length of the opposite and adjacent sides (e.g. 16:9);
    The triangle will always be right angled;
    I don't need to solve the length of the hypotenuse (unless it helps solve the other sides).

    Would it be easier to get the actual lengths then?
    The ratio could be interpreted as angles, that explains my earlier question.

    (This is about scaling a custom coordinate system relative to screen aspect ratio, if you're interested)

  6. #6
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    The law I'm using:
    Code:
    K = (a^2)(sinBsinC/sinA)/2
    
    K = area
    A, B, C = angles
    Solve for a:
    Code:
    K/(a^2) = (sinB*sinC)/(2*sinA) = 
    a^-2 = ((sinB*sinC)/(2*sinA))/(K) = (sinB*sinC)/(2*sinA*K)
    a^2 = ((sinB*sinC)/(2*sinA*K))^-1 = (2*sinA*K)/(sinB*sinC)
    a = sqrt((2*sinA*K)/(sinB*sinC))
    Now just swap in respective values for each side:
    Code:
    a = sqrt((2*sinA*K)/(sinB*sinC))
    b = sqrt((2*sinB*K)/(sinA*sinC))
    c = sqrt((2*sinC*K)/(sinA*sinB))

  7. #7
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    Quote Originally Posted by SMurf View Post
    Yeah, I did think about doing it iteratively, but I feel that I would end up doing a thousand calculations coming up with something quite simple.

    How about then, if:-

    Constant area, as before;
    I had the ratio of the length of the opposite and adjacent sides (e.g. 16:9);
    The triangle will always be right angled;
    I don't need to solve the length of the hypotenuse (unless it helps solve the other sides).

    Would it be easier to get the actual lengths then?
    The ratio could be interpreted as angles, that explains my earlier question.

    (This is about scaling a custom coordinate system relative to screen aspect ratio, if you're interested)
    It's not really iterative, you're guessing a side to find the ratio between area and side length for the given angles, then you just scale the side length according to the desired area.

  8. #8
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    I still think User Name:'s method involves less steps though.

    To reduce it based on what I've written (right-angled triangle, so sinC is always 1):-
    Code:
    a = sqrt((2*sinA*K)/sinB)
    Once you've found a, you can then switch to simpler terms:-
    Code:
    K = (a*b)/2
    b = (K*2)/a
    And that's a and b!

  9. #9
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Quote Originally Posted by SMurf View Post
    Code:
    K = (a*b)/2
    b = (K*2)/a
    And that's a and b!
    I don't see how you derived those... When given sinC = 1, you can eliminate it from the multiplication in the equation, but you can't just throw out random stuff with it.

    Code:
    a = sqrt((2*sinA*K)/(sinB))
    b = sqrt((2*sinB*K)/(sinA))
    c = sqrt((2*K)/(sinA*sinB))
    If you can simplify it more than that, please, show me.

    EDIT: Oh... Epy linked to Heron's formula like five posts ago. That's the name of the law/formula I used. Also, once you've got one side, you can do simple algebra with the law of sines and cosines to find the rest. Be careful with law of sines though, in special cases, it can give some weird output.
    Last edited by User Name:; 11-13-2010 at 09:44 AM.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    This shouldn't be impossible?
    Using the cosine law (don't know if sine's low would work in this equation, though):

    c = Sqrt(a^2 + b^2 - 2abcos(v1))
    b = Sqrt(a^2 + c^2 - 2abcos(v2))
    a = Sqrt(b^2 + b^2 - 2abcos(v3))

    3 equations, 3 unknowns.
    Messy equations, though, true. But possible I would think.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Elysia, the Law of Cosines requires 2 given sides, he has no sides. Heron's formula(the one I used) is required to find at least one side. Once you have one side, you can use Law of Sines, which, although much more efficient, can have weird results, or you can use all 3 I derived above, which will give correct results in all cases.

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    I am aware of that.
    I am also aware that this is an equation system.

    2abcos(v1...v3) are merely constants since v1...v3 are known.
    That leaves 3 unknowns and 3 equations which is enough to exactly solve the system.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    The equations are not independent.

    Just think about it logically. With just 3 angles, you can have infinitely many triangles.

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    *shrug*
    Maybe you're right. I didn't get a chance to test it due to Wolfram and their bloody license nightmare.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Of course I am right . No need for CAS. This is simple logic.

    If you scale all the sides equally, the 3 angles will be maintained.

    That's because the 3 angles are also not independent. The third angle is redundant information (180 - a - b). That's why we need another constraint - length of one of the sides.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic math programming question
    By hebali in forum C Programming
    Replies: 38
    Last Post: 02-25-2008, 03:18 PM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 02:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 02:24 AM
  4. Basic C question ---- URGENT
    By x135 in forum Linux Programming
    Replies: 3
    Last Post: 03-25-2006, 10:05 PM
  5. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 03:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21