Implementing XY instead of Polar Coordinates for Vbap Query.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implementing XY instead of Polar Coordinates for Vbap Query.

Nitram
This post was updated on .
Hi folks.

I'm trying to use an XYpad as a crude control to position sound within a 2d space using and 8 channel Vbap setup. As Vbap works in angles ranging from 0 to 360 degrees (as in below image) in a scenario that does not correspond at all to the way trigonometric angles are usually set up, I'm having lots of trouble working this out.


As this is a math issue, I posted the query in a maths forum and these are the instructions I got back:

r=x2+y2‾‾‾‾‾‾‾√r=x2+y2

θ=arctan⁡(xy) for 0<θ<90∘ ... i.e. both x & y positive

θ=180∘+arctan⁡(xy) for 90∘<θ<270∘ ... i.e. y negative

θ=360∘+arctan⁡(xy) for 270∘<θ<360∘ ... i.e. x negative, y positive


I'm currently trying to implement these equations, but the results do not correspond to what they should be (Also I get crashes if the XY coordinates are at 0).

My current code can be found in the next post. Would anyone care to offer some advice, please and thank you?



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing XY instead of Polar Coordinates for Vbap Query.

Nitram
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Implementing XY instead of Polar Coordinates for Vbap Query.

Anton Kholomiov
Hi, Martin!

My guess that the problem is with

taninv(kX / kY)

If kY is zero you should get divizion by zero error. 
This is very common case to get the polar coordinates.
It's so common that there is a special function that doesn't brakes on zero input taninv2:


Also note that taninv output is in radians not in degrees! 
So to get degrees you need to rescale it

taninv or taninv2 output lies in -pi/2 to pi/2 and if you want it to be -180 to 180
you need to do

ksig * 180 / (pi * 0.5)

also do you have a center in the left top-most corner? or is it placed in the middle of XY-pad
If it's in the middle you have to do:

kx1 = kx - kcenterX
ky1 = ky - kcenterY


Hope this helps!
Anton






2017-02-27 17:40 GMT+03:00 Nitram <[hidden email]>:
<http://csound.1045644.n5.nabble.com/file/n5754855/Code.png>



--
View this message in context: http://csound.1045644.n5.nabble.com/Implementing-XY-instead-of-Polar-Coordinates-for-Vbap-Query-tp5754854p5754855.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Implementing XY instead of Polar Coordinates for Vbap Query.

Nitram
Thanks for replying, Anton.

I'm trying to follow your instructions so I have input the data as follows.


The angles shown by the print are way off so clearly I'm doing something wrong.

Also this circle goes from 0-360 degrees, as shown in the image in my first post. You mentioned something about "-180 to 180".

Thanks!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Csnd] Implementing XY instead of Polar Coordinates for Vbap Query.

Anton Kholomiov
I'm doing that kind of thing by trial and error myself. But the thing I see from the code

you reversed the arguments for taninv2. it should be:

taninv2 ky, kx

not kx, ky

Also my guess is that taninv2 expects the Oy axis to point to up but in UI widgets like XY-pad it's often points to down.
So maybe you need to reverse the Oy by negotiation

ky1 = - (ky - kCenterY)

And I think that you don't need to check whether kX or kY are positive or negative it should be built in the taninv2


2017-02-27 20:54 GMT+03:00 Nitram <[hidden email]>:
Thanks for replying, Anton.

I'm trying to follow your instructions so I have input the data as follows.
<http://csound.1045644.n5.nabble.com/file/n5754857/Conundrum.png>

The angles shown by the print are way off so clearly I'm doing something
wrong.

Also this circle goes from 0-360 degrees, as shown in the image in my first
post. You mentioned something about "-180 to 180".

Thanks!



--
View this message in context: http://csound.1045644.n5.nabble.com/Implementing-XY-instead-of-Polar-Coordinates-for-Vbap-Query-tp5754854p5754857.html
Sent from the Csound - General mailing list archive at Nabble.com.

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Loading...