Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
struggling w/ sin and cos
#1
geez, i'm having so much trouble understanding this, i've looked at tutorials, and the like..but none of them seem to be very clear... here's a pic

[Image: faq.trigfunc.circle.gif]

now, lets say we want a pixel that moves in a circle around the screen.. would the pixel "ride" on Q? and how does R's value change where Q is going??? my head hurts...
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#2
If you're using radians for the angle measurement (you should, since that's what sine and cosine implementations on a computer use), then x (the angle) ranges from 0 to 2 * pi.

Code:
option explicit

const pi as single = 3.141592654
dim angle as single
dim center_x as integer, center_y as integer
dim radius as integer

radius = 90    ' radius of the circle (distance from center to any point on the circle)


center_x = 320 \ 2    ' center of circle
center_y = 200 \ 2

screen 13

for angle = 0 to (2 * pi) step (pi / 256)
    pset (    center_x + cos(angle) * radius, _
        center_y + sin(angle) * radius ), 15
    sleep 10
next angle

do while len(inkey) = 0
loop
Reply
#3
um..ok, here's a question

1.is cos the distance between "R" and "O" ?

2.is sin the distance between "R" and "Q" ?
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#4
Yes, Sin is for Y, Cos is for X

H = your hypotinuse, or in this case, the radius of you circular pattern.. but since where going for intended circular pattern to a X Y cord on the screen, think of it as the hypotinuse..

Sin is for Y, So, for it to become the distance we use..

Sin (Angle) = O/H

If you had O, the distance between "R" & "Q", and divided it by H (Which in your diagram equals 1) you'd get the Sin of the angle, in turn that can give you the angle.. This can be reversed tho so if you have the angle:

O = H * SIN (angle)

Now O = Distance from "R" & "Q" then subtracting that from the center of your screen will give you the Y cord..

Y = O - ScreenCenterY

Same for X except you add the screen center..

A = H * COS (angle)
X = A + ScreenCenterX

And you most convert Degrees to Radians for this to work in a program:

angleR = angle * 3.14 / 180

Then

O = H * SIN (angleR)
Y = O - ScreenCenterY
A = H * COS (angleR)
X = A + ScreenCenterX

And this is just a overview, its a litte more to 2D and 3D.. :wink:
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#5
[Image: unit-circle.gif]
Reply
#6
hey, thnx, that diagram helps quite a bit.. i got a question tho.. whats the little symbol that looks like a zero? but, not quite like a zero, more like a helecopter landing pad?
url=http://www.random-seed.net][Image: asylumsig.png][/url]
Reply
#7
Greek letter uppercase theta
Reply
#8
here is some more trig diagrams.
[Image: quadrants.gif]
[Image: 60-refrance.gif]
[Image: sin-wave.gif]
Reply
#9
Smile Heh, a Tranverse wave Sin diagram, you just throw that in for the heck of it, he's trying 3D rotations, not drafting sound waves... :wink: oh well, :roll: ...
Kevin (x.t.r.GRAPHICS)

[Image: 11895-r.png]
Reply
#10
Those diagrams are good and all, but do yourself a favor and get used to radians. It will make your life much easier in more advanced math classes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)