×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!
• Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Trigonometry

 Forum Search FAQs Links MVPs

Trigonometry

(OP)
I really need help on these qbasic functions. I learned a little about these in my math class, but I don't really see how it applies to qbasic. And since I'm not getting into trig this year at school I need help. Does anyone know any sites where I can find information about these functions?

RE: Trigonometry

The BASIC trig functions are
COS - cosine in radians
SIN - sine in radians
TAN - tangent in radians
ATN - cotangent in radians

Have use ever heard of SOH-CAH-TOA?
sin x = opposite/hypotenuse
cos x = adjacent/hypotenuse
tan x = opposite/adjacent

Trig is used to do mathematical calculations with triangles and using angles and the lengths of the sides to find anything that you need.

Trig functions are usually used in qbasic for three-dimentional programming, but of course could be used for anything that you need.

RE: Trigonometry

if you EVER want to make a raycaster, isometric engine, wireframe engine, or whatever, you will need to know these. but you know what? my advice is not to worry abou them until you take it up in school.  `

RE: Trigonometry

Nah...

Trig is easy, once you understand it...

Take a look at the visual description I made a while back...

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

(OP)
I'm not getting into 3d graphics yet. I understand what the functions are used for, but I don't understand how exactly. I'm mainly focusing on this for 2d rotations and other effects. I've experimented a lot, but I'm not sure if I'm doing anything right. I just hope some of the programs I make using the functions work out. Like this:

SCREEN 13
pi = 3.141592654#
RANDOMIZE TIMER
DO
LINE (160, 100)-(degrees, degrees2), 0
x = x + 1
y = y + 1
degrees! = COS(x) * 180 / pi + 160
degrees2! = SIN(y) * 180 / pi + 100
CIRCLE (degrees!, degrees2!), 7, INT(RND * 255)
LINE (160, 100)-(degrees, degrees2), INT(RND * 255)
WAIT &H3DA, 8
LOOP

All I did was find out how to convert radians to degrees and the rest I just experimented with. The things I need to know are what are the trig functions actually giving me? What are radians? And heck why that program up there works?
Thx for the visual CubeE101, but I don't get how that applies to qbasic when it finds the cos and sin of a number. I get how it works in "normal" math tho. Thx for all the info you've given me so far its been helpful.

RE: Trigonometry

no...

You have it backwards...

Use them like this...

Const Pi = 3.141592654#

Sub AngLine(X1, Y1, Degree, Radius, Color)
X2 = X1 + (Cos(Degree * Pi / 180) * Radius)
Y2 = Y1 + (Sin(Degree * Pi / 180) * Radius)
Line (X1,Y1)-(X2,Y2), Color
End Sub

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

Or... if you want to draw a circle...

Const Pi = 3.141592654#

Sub DrawCirc(X, Y, Radius, Color)
For Deg = 1 To 360
X1 = X + (Cos((Deg - 1) * Pi / 180) * Radius)
Y1 = Y + (Sin((Deg - 1) * Pi / 180) * Radius)
X2 = X + (Cos(Deg * Pi / 180) * Radius)
Y2 = Y + (Sin(Deg * Pi / 180) * Radius)
Line (X1,Y1)-(X2,Y2), Color
Next
End Sub

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

What he was showing you in the graphic above is what is known as the unit circle.  The parent function always has its centre at (0,0) and has 1 for a radius.  Then the position of B in the graphics (cos A, sin A) where A is the angle.

RE: Trigonometry

Yes...

This is also moving into Vectors...
A Vector is...
An element with a base point at X,Y(,Z)
A direction (Angle)
And A Magnitude (Length)

A "Normal Vector" is...
A Vector with the magnitude equal to 1

This Vector Can then be scaled, by multiplying...

So you use the Base Function...
X = Cos(Angle)
Y = Sin(Angle)

Which will give you the coordinates (X,Y) of a point relative to Zero (0,0) that represents a direction and a length of 1 (Which is also known as a normal vector)

You Can then Scale the vector by multiplying Both the X and the Y equations by the Same Number...
X = Cos(Angle) * Length
Y = Sin(Angle) * Length

You can also Translate the base coordinates by adding a value to the product of those equations...
X = BaseX + (Cos(Angle) * Length)
Y = BaseY + (Sin(Angle) * Length)

So if you Want to Draw A line starting at (3,5) and extending 10 units at 45 degrees...

BaseX = 3
BaseY = 5
Length = 10
Angle = 45 * Pi / 180     'MUST BE IN RADIANS TO WORK
X = BaseX + (Cos(Angle) * Length)
Y = BaseY + (Sin(Angle) * Length)

Line (BaseX, BaseY) - (X, Y)

It's that simple
----------------

There are also many other uses for Sin & Cos...
If you Plot Y as a funtion of X, such as...

Screen 13
For X = 1 to 320
Y1 = 100 + (Sin((X-1) * Pi / 180) * 50)
Y2 = 100 + (Sin(X * Pi / 180) * 50)
Line (X, Y1) - (X, Y2)
Next

You Will notice that this creates a Wave...
This is known as a Sine Wave
Cosine Creates A Similar Effect, but is offset from the Sine Wave...

Screen 13
For X = 1 to 320
Y1 = 100 + (Cos((X-1) * Pi / 180) * 50)
Y2 = 100 + (Cos(X * Pi / 180) * 50)
Line (X, Y1) - (X, Y2)
Next

You can do many things With these functions such as warping pictures, shifting colors, and many other stange effects, just by tweaking the above formulas and using your imagination...

For an example of what all you can do with Sin & Cos... Download LudaTRIS from my site... it is a wack tetris game I made a few years ago, that uses Sin & Cos functions For the Intro Thread effect, Color Shifting, and Warping the Screen... (I believe you hold 'W' to add to the 'Wave' Effect...

The source code is also there for you to download...

I Hope This Helps...
And Have Fun ,
Josh S

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

If you are unfamiliar with the sine wave you can see it by doing this

SCREEN 12
FOR a% = 0 TO 360
ang = a% * 3.14159 / 180
PSET (a%,ang * 10 + 100)
NEXT

The cosine will give you that same thing but offest by exactly -pi/2

If you know about calculus you will also notice that the cosine and sine graphs are derivatives of each other, but since you haven't taken trig yet, you probably wouldn't know that.  Thats not important to know for trig programming, its just a little FYI

RE: Trigonometry

(OP)
You actually made me understand the basic forms of trig....man, you people are geniuses. I pretty much understand it now. Great now I need to get into the inverse and hyperbolic and complex stuff like that....but I'll live. Thx so much you've really helped me out.

RE: Trigonometry

Ok... So you have your basic Right Triangle...

Where...
Line A is the Height (Y or Rise)
Line B is the Length (X or Run)
Line C is the Hypotenuse (Radius)

Angle a is Opposite Line A
Angle b is Opposite Line B
Angle c is Opposite Line C (and is always 90 degrees)

For the functions to work, the Triangle must be Normalized...
So, Assume the Hypotenuse (C) is 1 unit in length
And ALL angles are in Radians (Degree * Pi / 180)

----Sine and Cosine-----
Sin(a) = B / C
-so-
Sin(a) * C = B
-or-
B / Sin(a) = C

Cos(a) = A / C
-so-
Cos(a) * C = A
-or-
A / Cos(a) = C

----Tangent and Arch Tangent-----
*Note: A / B is also known as Rise over Run AKA slope
Tan(a) = A / B
-so-
Tan(a) * B = A
-or-
A / Tan(a) = B

ArcTan (ATN) is the opposite of Tan
Atn(A / B) = a

So they cancel each other out...
Tan(Atn(A / B)) = A / B
-or-
Atn(Tan(a)) = a

Other Functions can be derived from these base functions...

Secant: Sec(X) = 1 / Cos(X)
Cosecant: Cosec(X) = 1 / Sin(X)
Cotangent: Cotan(X) = 1 / Tan(X)
Inverse Sine: Arcsin(X) = Atn(X / Sqr(-X * X + 1))
Inverse Cosine: Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)
Inverse Secant: Arcsec(X) = Atn(X / Sqr(X * X – 1)) + Sgn((X) – 1) * (2 * Atn(1))
Inverse Cosecant: Arccosec(X) = Atn(X / Sqr(X * X - 1)) + (Sgn(X) – 1) * (2 * Atn(1))
Inverse Cotangent: Arccotan(X) = Atn(X) + 2 * Atn(1)
Hyperbolic Sine: HSin(X) = (Exp(X) – Exp(-X)) / 2
Hyperbolic Cosine: HCos(X) = (Exp(X) + Exp(-X)) / 2
Hyperbolic Tangent: HTan(X) = (Exp(X) – Exp(-X)) / (Exp(X) + Exp(-X))
Hyperbolic Secant: HSec(X) = 2 / (Exp(X) + Exp(-X))
Hyperbolic Cosecant: HCosec(X) = 2 / (Exp(X) – Exp(-X))
Hyperbolic Cotangent: HCotan(X) = (Exp(X) + Exp(-X)) / (Exp(X) – Exp(-X))
Inverse Hyperbolic Sine: HArcsin(X) = Log(X + Sqr(X * X + 1))
Inverse Hyperbolic Cosine: HArccos(X) = Log(X + Sqr(X * X – 1))
Inverse Hyperbolic Tangent: HArctan(X) = Log((1 + X) / (1 – X)) / 2
Inverse Hyperbolic Secant: HArcsec(X) = Log((Sqr(-X * X + 1) + 1) / X)
Inverse Hyperbolic Cosecant: HArccosec(X) = Log((Sgn(X) * Sqr(X * X + 1) + 1) / X)
Inverse Hyperbolic Cotangent: HArccotan(X) = Log((X + 1) / (X – 1)) / 2
Logarithm to base N: LogN(X) = Log(X) / Log(N)

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

(OP)
thx cubee for explaining that so well. It seems really complicated. BTW what are these formulas used in programming for? thx again

RE: Trigonometry

The main ones that I use are Sin & Cos...

You can, however, use ArcTan (ATN) to get an angle from point to point, for example, if you use a mouse routine, and want to get the angle between 2 mouse clicks...

The rest of them might be useful if you are writing a CAD (or similar) program. otherwise, I have no idea...

Have Fun, Be Young... Code BASIC
-Josh

http://cubee.topcities.com

RE: Trigonometry

(OP)
thx I need all the help i can get

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.