Angle and distance in an XY Pad
Hi,
It's more a math question than an patching question, but here's the idea.
To control Ambisonic plugins, I want to get the angle (0 to 360) and the distance (0 to 1) of a ball in an XY pad, relative to the center.
Examples :
Ball at the middle = angle of 0, distance of 0.
Ball at upper left corner = angle of 135, distance of 1.
Ball at bottom right corner = angle of 315, distance of 1.
Anyone have an idea ?
- Guillaume
It's more a math question than an patching question, but here's the idea.
To control Ambisonic plugins, I want to get the angle (0 to 360) and the distance (0 to 1) of a ball in an XY pad, relative to the center.
Examples :
Ball at the middle = angle of 0, distance of 0.
Ball at upper left corner = angle of 135, distance of 1.
Ball at bottom right corner = angle of 315, distance of 1.
Anyone have an idea ?
- Guillaume
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
about the distance you can find an example in the addon named Morphusine
the match formula is
distance = /¯ [ (X1-X2)² + (Y1-Y2)²]
i will look if if i find about angle
the match formula is
distance = /¯ [ (X1-X2)² + (Y1-Y2)²]
i will look if if i find about angle
Thanks !
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
I've found a solution. I don't totaly understand the maths (i've found the formula on the web), but it works.
Here is the script :
Here is the script :
Code: Select all
var xIn : Tparameter;
var yIn : Tparameter;
var angleOut: Tparameter;
var distanceOut: Tparameter;
procedure init;
begin
xIn := CreateParam('x',ptDataField); SetIsOutput(xIn,false);
yIn := CreateParam('y',ptDataField); SetIsOutput(yIn,false);
angleOut := CreateParam('angle', ptDataField ); setIsInput(angleOut,false);
distanceOut := CreateParam('distance', ptDataField ); setIsInput(distanceOut,false);
end;
function sgn (a : real) : real;
begin
if a < 0 then sgn := -1
else sgn := 1;
end;
function atan2 (y, x : real) : real;
begin
if x > 0 then atan2 := arctan (y/x)
else if x < 0 then atan2 := arctan (y/x) + pi
else atan2 := pi/2 * sgn (y);
end;
Procedure Callback(n:integer);
var x:single;
var y:single;
var angle:single;
var distance:single;
begin
if (n=xIn) or (n=yIn) then begin
x := (getValue(xIn) - 0.5);
y := (abs(getValue(yIn) - 1) - 0.5);
//angle
angle := atan2(x,y) * 180 / pi;
if angle < 0 then angle:= angle + 360;
setValue(angleOut, round(angle));
//distance
distance := sqrt(x*x + y*y);
setValue (distanceOut, distance);
end;
end;Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
Does anyone knows how I can reverse those formulas ?
Getting X-Y from angle and distance ?
Guillaume
Getting X-Y from angle and distance ?
Guillaume
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
cool, but how do you use it..?
don't have anything from the out of the script...
don't have anything from the out of the script...
If you connect the pos-X, pos-Y out of a XY Pad to the in of the script, it should work.
It works on my side...
It works on my side...
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
strange , i see something in , nothing out...
the script seems to be perfect!
to reverse the formula:
x = distance*cos(angle)
y = distance*sin(angle)
to reverse the formula:
x = distance*cos(angle)
y = distance*sin(angle)
Olivier Sens
www.brainmodular.com
www.brainmodular.com
ok, forget it , was experimenting too much thing in the same time ..
works fine
works fine
Thanks Senso,
It works !
The only thing, is that if you want to control angle with a value from 0 to 360 the formula should be :
x = distance * cos(angle/360*pi*2)
y = distance * sin(angle/360*pi*2)
It works !
The only thing, is that if you want to control angle with a value from 0 to 360 the formula should be :
x = distance * cos(angle/360*pi*2)
y = distance * sin(angle/360*pi*2)
Guillaume Thibert
www.cemproduction.com
www.cemproduction.com
Who is online
Users browsing this forum: No registered users and 12 guests
