Advertisement

math question

Started by January 10, 2004 06:34 AM
8 comments, last by TykeiL 21 years, 1 month ago
ok, i have my x coordinate oscilating left and right using sin and i have my y coordinate oscilating up and down using cosine now i want my x coordinate to equal zero when my y coordinate reaches its peak not an easy thing for the mathamatically ungifted xpos = sin(mynumberx)???; ypos = cos(mynumbery); keypress mynumberx+=0.01; keypress mynumbery+=0.01; the questionmarks are for what to put here, it has something to do with ypos im sure, but i dont know enough about maths, i cant use the normal ad subtract multiply or divide cause they dont work, the results are undesirable. im not fussed if nobody knows the answer its just curious as to why this seeming simple thing i want done just aint gonna happen. im racking my brain, !!My bRaiN is FiLLEd With HappY Juice!! [edited by - TyKeiL on January 10, 2004 7:43:31 AM] [edited by - TyKeiL on January 10, 2004 5:59:07 PM]
!!My bRaiN is FiLLEd With HappY Juice!!
Well, sounds like to me you want to move something in a circle, in which case, you almost have it right.

y = a * sin( theta )
x = a * cos( theta )

Increase theta depending on where in the circle that something is. Bear in mind that theta is in radians, and a is the radius of the circle.

You have to remember that you''re unique, just like everybody else.
If at first you don't succeed, redefine success.
Advertisement
python_regious: cheers for the answer, and my equasion was correct for a circle if i only wanted a radius of 1, i have modified the question again, to remove ambiguity

what i want is for my x oscilation to be reduced to zero if my y coordinate is at its peak, i have removed there reliance on each other

i dont want a circle, :O)

!!My bRaiN is FiLLEd With HappY Juice!!
!!My bRaiN is FiLLEd With HappY Juice!!
sin() and cos() are defined such that the cos() will return 0 when sin() is at its peak, and vice versa. Thus, then ONLY way that you will get what you want is to feed the same number (theta) into the cos() and the sin() calls.

If you want an ellipse, scale the output (not input) of cos() and sin() differently. If you want a slanted ellipse, send the output (not input) of those valuse through a rotation matrix.
enum Bool { True, False, FileNotFound };
ok heres what i think it should look like since my explinations dotn cut it a picture will have to do



currently i have
tarposx = (float)sin(camrotx)*tarposy;
tarposy = (float)cos(camroty);
i have 4 keys each pair raising or lowering the camrot's
with this way i get




[edited by - TyKeiL on January 10, 2004 6:30:59 PM]

[edited by - TyKeiL on January 10, 2004 6:32:36 PM]
!!My bRaiN is FiLLEd With HappY Juice!!
Try this:

xpos = sin(mynumberx) * sin(mynumbery);
ypos = cos(mynumbery);
Advertisement
well, since what you have and what you want are very similar, you dont need to change much. have you tried adding/subtracting PI to camroty?
Just a guess.
its easy just look at it! its a sine wave, thats peak value is rising and faaling like a sine wave. So you need a simple function:

y=f(x)=sin(x)*cos(x)

i hope iam right (have nothing to check it with)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
orbano: you are on the right track. I was playing around on my graphing calc, and I came up with f(x)=5*cos(x)*sin(10*x).
That makes the general equation for this type of function
f(x)=a*cos(f1*x+p1)*sin(f2*x+p2)
where a is the amplitude, f1 and f2 control frequency, and p1 and p2 control phase.
tarposx = (float)sin(camrotx)*cos(camrotz);
tarposy = (float)cos(camrotx)*cos(camrotz);
tarposz = (float)sin(camrotz);

got it :O) now using 2 axis of rotation ie the mouse movement, i can rotate my point around an origin in a spherical manner.

this is for a camera., ive been so confused by other peoples equasions to work out the camera target positioning, it all seemed to complicated for something which should be simple enough.

so the target vector is equal to the target position minus the camera position
tavectx = tarposx-camposx; etc

the only problem i have now is finding the up vector based on the target vector i have been racking my brain to figure out the relationship between the up vector and the target vector. esp since they are fixed to each other

then the last thing will be to roll the camera which should be fun =P

man camera''s are good to have, but only a good camera is good to have, im sick of dodgy camera''s that are half arsed i want to make a great one
!!My bRaiN is FiLLEd With HappY Juice!!

This topic is closed to new replies.

Advertisement