Results 1 to 8 of 8

Thread: Faster sine/cosine?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Holland
    Posts
    10

    Question

    Isn't there a faster way to calculate sine/cosine?

    After I included about 60 sine/cosine functions per frame my framerate went down by about 1000(!)%

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It's because they use your math processor. You need to setup a trignonometry table by declaring arrays and store the trig functions results in them. Then use these arrays instead of vb's trignonometry functions.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Posts
    123
    Wouldn't this limit presision depending on how far the function is caried out in the array... if he wants to stay acurate to say 5 or 6 decimal places the vbTrig functions might be the most practical way. ( I think... but I have been wrong in the past)

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    If you don't have memory problems you can make your table as huge as you want, it depends on what you're doing, you said your having frame rates, i guess youre working on a 3d-engine, i had the same problem solved it this way.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    I remember once writing a program to rotate a 3d matrixed box. I just threw in a heap of constants because they compile to just their values.

    A better way would be to calculate a whole heap of trigs on form load and write them to an array, then just call them.

    Instead of X=Cos(45) (the function)

    you have X = MyCos(45) (the array)

    where the index was written with the cos of that number

    It also means you can work directly in degrees and not radians.

    Dim MyCos(360) as single
    I = 45
    MyCos(I) = COS(I) '(*180/pi) or whatever it is to convert from radians.

    so MyCos(i) = 0.70711

    Sorry for the math, it's early and I can't be bothered working it out exaclty, you get the idea
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Holland
    Posts
    10

    Talking

    The (co)sine table will do fine. I think I won't need much more than 1 value/degree.

    Thank you for your replies!

    -Musashimaru

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Is that MusashiMaru as in the Hawaian Sumo Wrestler?
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Holland
    Posts
    10

    Talking

    O yeah!

    btw. It's only a nick. I'n not (shock!) the real Musashimaru :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width