1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Maths/C Question

Discussion in 'HTML, Graphics & Programming' started by NotAGolf, 16 Sep 2009.

  1. NotAGolf

    Wise Guy

    Joined: 22 Oct 2005

    Posts: 2,447

    Location: Moving...

    Could someone help me out with the following equation please. I'm trying to calculate the following equation in C:

    Code:
                                 1
    C =   ---------------------------------------------------
             sqrt( cos^2(latitude) + (1-f)^2 * sin^2(latitude) )

    First off, is there a function in C to do cos or sin^2(x)? I coulnd't find one, just the ordinary sin/cos functions.

    Because I couldn't find out how to do that, I used the following trig identities which I found:

    Code:
    cos^2(x) = 1/2 + 1/2 cos(2x)
    and
    sin^2(x) = 1/2 - 1/2 cos(2x)
    Are these correct?

    Thanks for any help!
     
    Last edited: 16 Sep 2009
  2. NotAGolf

    Wise Guy

    Joined: 22 Oct 2005

    Posts: 2,447

    Location: Moving...

    Sorry I'm being a massive spanner. The function works fine now. I just can't tell the difference between longitude and latitude :o:o:o.

    The first question still stands though, is there a function for sin/cos^2(x)?

    Cheers.
     
  3. azteched

    Gangster

    Joined: 9 Jun 2004

    Posts: 423

    cos^2(x) means (cos(x))^2 ...

    double c = cos(x)
    double cc = c*c /*cc = cos^2(x)*/
     
  4. BullBoyShoes

    Gangster

    Joined: 21 Jan 2005

    Posts: 346

    it depends on what platform your running the code on. Most efficient way would be a look up table of precalculated values
     
  5. Inquisitor

    Capodecina

    Joined: 12 Apr 2004

    Posts: 11,788

    Location: Birmingham

    They're correct, but as azteched said, you may as well just calculate the cosine once and then multiply it by itself. It's far cheaper in terms of processing time (not that something so trivial should make any real difference anyway).

    Or just use the cos function? :confused:
     
  6. Makhaira

    Mobster

    Joined: 23 Nov 2007

    Posts: 4,854

    Location: Lancashire, UK

    sin/cos = tan. So you can simplify that down to just tan/cos.
     
  7. BullBoyShoes

    Gangster

    Joined: 21 Jan 2005

    Posts: 346

    thats why I said its dependant on the platform its running on. You wont find any trig libraries on an 8-bit micro