Hallo, alexandre r. decoupigny hat gesagt: // alexandre r. decoupigny wrote:
sorry abou that.. dont have any number example in the top of my head.. what i know is that [joystick] outputs numbers between zero and one on two outlets (x axis and y axis). now i wonder how to put these numbers together with a horizontal slider that represents a circle. this horizontal slider outputs values from 0-360 each representing a point on a circle. i dont know if i made my problem any clearer..
Lets first summarize where you are already:
You could think of the Joystick as drawing a circle. If you scale both outlets of the joystick to go from -1 to 1 you would basically have a unit circle described by the Joystick's movement. Scaling from (0,1) to (-1,1) is easily made with x*2-1 rsp. y*2-1
Now you can get the tangent of the angle in a joystick's position by just divinging opposite and adjacent sides of the triangle made by the angle, or in joystick coordinates this is: y/x=tan(phi) ==> phi=atan(y/x)
In Pd you use [atan2] for this and according to the help-patch this works like this:
"The arc tangent takes two forms. The atan2 version takes an (x, y) pair and gives you an output between -pi and pi."
Which is an angle in radians!
So that's where you are: You want to map a range (-pi,pi) to a range (0,360). It's actually easy as well: Assume z=atan2(x,y), range (-pi,pi)
z/pi will be in a range (-1,1) then.
180*z/pi will be in (-180,180) (this is what rad2deg.pd from zexy (?) gives you.
180 + 180*z/pi will be in (0,360)
Done.
Now what is left is how to get PI? I just use [expr 4*atan(1)] normally. I have it in an abstraction called [M_PI].
Frank Barknecht _ ______footils.org_ __goto10.org__