Author Topic: Tangent?  (Read 12265 times)

0 Members and 1 Guest are viewing this topic.

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Tangent?
« on: May 07, 2012, 08:02:03 pm »
Is there a way tangent could be implemented? I've tried sin/cos, but I always get something really small, usually 0, 1, or 2 (I think). I'm making a shooter that has angled bullets for shiggles because I have nothing to do in my pre-calc class now that it's AP season (my tests are towards the end), and right now I just use a sort of slope method, but I figured it might possibly be easier/better in some way to use an angle. Then again, I've been wrong before ^^

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Tangent?
« Reply #1 on: May 07, 2012, 08:08:18 pm »
Could you give us a sample please?
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Tangent?
« Reply #2 on: May 07, 2012, 08:12:27 pm »
Xspeed = cos(θ) * speed
Yspeed = sin(θ) * speed

That should get the job done right?
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Tangent?
« Reply #3 on: May 07, 2012, 08:45:15 pm »
Basically what I have is all of my bullets' data stored in L1, with the format being this:

Offset | Meaning
n+0    | ^r = X
n+2    | ^r = Y
n+4    | Slope
n+5    | Flag for up/down


Now, I do realize I don't need the word-sized X and Y, but I didn't feel like working with one-byte variable numbers while I was writing this. Anywho, basically what id does right now is at every update the X is incremented by 1 and if X^slope is zero, I change Y based on the flag. Right now it works fine, but my question was instead of doing a slope, would it be easier to have something like tangent be used to calculate an angle? (I just remembered it's arctan(Y/X) = angle, not the other way around >.<)
« Last Edit: May 07, 2012, 08:45:33 pm by BlakPilar »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Tangent?
« Reply #4 on: May 07, 2012, 09:30:55 pm »
Instead of using slope and a flag, would it not be easier to use just an angle instead?  That way you can specify the full range of directions in equal precision, and it would take up less data and use already implemented Axe commands.  Your slope would range from 0 to 256, where 0 is directly to the right, 64 is directly down, 128 is directly to the left, and 192 is directly up.  To extract the directions from the angle, simply use Cos(angle) for the X direction and Sin(angle) for the Y direction

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: Tangent?
« Reply #5 on: May 07, 2012, 09:33:20 pm »
Instead of using slope and a flag, would it not be easier to use just an angle instead?

Precisely my initial question lol. But I don't need to worry about left/right movement. The bullets start on the left side of the screen in the middle, and are fired so they go to the right either up or down.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Tangent?
« Reply #6 on: May 07, 2012, 10:31:47 pm »
Well using an angle method still works well, and if this is for some sort of shooter game, that means you can re-use some code for any bullets that are being fired back at you :D

Offline Wretchedlout

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +6/-0
    • View Profile
Re: Tangent?
« Reply #7 on: May 07, 2012, 10:48:34 pm »
Couldn't you derive it?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Tangent?
« Reply #8 on: May 07, 2012, 11:09:01 pm »
Derive what?

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Tangent?
« Reply #9 on: May 07, 2012, 11:15:21 pm »
Tangent as in the trigonometric function, not the slope of a line at a point =P  So, no there is nothing useful to derive here...
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Tangent?
« Reply #10 on: May 08, 2012, 05:57:02 am »
Yeah I would pretty much like a tan( function.
I'm not a nerd but I pretend:

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Tangent?
« Reply #11 on: May 08, 2012, 09:42:24 am »
I feel like this would work:
Code: [Select]
Lbl Tan
Return sin(r1)*256//cos(r1)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Tangent?
« Reply #12 on: May 16, 2012, 10:56:55 pm »
Why *256? tan(angle) is defined as y/x, and with sin(angle) and cos(angle) being y/r and x/r respectively, tan(angle) can also be defined as sin(angle)/cos(angle), so i dont see why you would multiply sin(angle) by 256 first.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Tangent?
« Reply #13 on: May 17, 2012, 02:40:27 am »
Why *256? tan(angle) is defined as y/x, and with sin(angle) and cos(angle) being y/r and x/r respectively, tan(angle) can also be defined as sin(angle)/cos(angle), so i dont see why you would multiply sin(angle) by 256 first.
Else you would lose precision, as the division in Axe doesn't care about the remainder. For example, 7/2=3.5 but in Axe, 7/2=3 (if you don't do floating point math of course ;))
This is also why cos and sin return between -127 and 127 because if it returned between -1 and 1, it would always be 0
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Tangent?
« Reply #14 on: May 17, 2012, 03:58:23 pm »
But multiplying by 256 just changes it from something like $00A6 to $A600. It doesnt increase precision, but just changes the value. sin($A600) is completely different than sin($00A6).