# Math question: Radial Motion



## paoling (Apr 1, 2014)

Hi to all!
I'm working on a lib which should allow to pick some sounds around a circle and morph between them when you move around (or inside) the circle. Everything's fine, I managed to make the point to stay inside the circle and so on.

Now, I'd like to be able to set some "states", positions of the morphing point that can be effectively triggered in someways by the script. The idea is to be able to make a kind of morphing between two states, by moving the point inside the circle.

There are two main ways to accomplish this: the first one is a linear interpolation using the coordinates of the point, the second one is a kind of "radial motion", so the point moves around the center of the circle in a radial way, like a clock and it's distance from the center is adjusted by the difference of the distance of the first point and the second one.

Here I attached an example of what I mean (not very accurate, but it can be just an idea). How could I do this?

The distance of the point C from the center can be linearly interpolated by using the distance A and the distance B. But how can I achieve a kind of clock motion around the center?


----------



## mk282 (Apr 1, 2014)

I'm certain that you will find a lot of use for that in trig functions like sin(x).


----------



## paoling (Apr 1, 2014)

Yes but the problem with Math Library is that I don't have the inverse functions, so I can't retrive the angle of A and the angle of B. But it's probably a problem of my rusty maths skills from the school :-D

Edit: I'm discovering that maybe I just need a way to convert the xy axis coordinates system with polar coordinates, which actually are pairs of distance from a center and an angle.


----------



## mk282 (Apr 1, 2014)

Polar coordinates should work, too, yeah. :D

But regarding math library, sin/cos functions use decigrads, where 1000 is 90 degrees. You should be able to calculate the angle with this info.


----------



## paoling (Apr 1, 2014)

Ok, maybe we just need to find a good ArcTan function. I'll post what I can find here.


----------



## paoling (Apr 1, 2014)

I found this little formula for tang values of (0.100), the last instruction is made to make it compatible with the 1000 scale of Math Library

function arctan(x) -> result; 
x:=abs(x)
result:=0; 
if x>=0 
for i:=1 to x 
result:=result+10000/(100+i*i/100); 
end for
{range is 0 to 15600}
end if 
result:= result*1000/15600
end function


----------



## TGV (Apr 1, 2014)

So you want a parametric path from A=(xa,ya) to B=(xb,yb), so some f(A, B, t), but how precisely? The drawing is a bit unclear. If I interpret you right, you want to simultaneously move the angle from A to B while interpolating the radius from center from A to B.


----------



## Big Bob (Apr 1, 2014)

paoling @ Tue Apr 01 said:


> Ok, maybe we just need to find a good ArcTan function. I'll post what I can find here.



You can rather easily modify the Math Library's Cordic for SinCos to compute Arctan. The general idea is instead of driving the input angle to zero with the cordic rotations, you set the initial angle to zero and drive the Y value to zero with the cordic rotations. When the iterations end, the angle will be in z and X will be the scaled hypotenuse. ie if you start with any given X,Y (the rectangular coordinates), you will end up with Z=ang, Y = 0, and X = kR where R is the radius vector (thus Z and X are the polar coordinates).

I never even thought of adding any inverse trig functions to the library because until now, no one ever expressed any interest in them :lol: 

Rejoice,

Bob


----------



## paoling (Apr 8, 2014)

Thank you Bob, and sorry for the delay in the answer. Actually I tried to look and to reverse the SinCos function to adapt it to compute ArcTan. I suppose it's a matter of almost changing the coefficients in the array, but I still don't totally grasp the theory behind it to make it right.

But I did a step by step system, by using the above formula to calculate the ArcTan, then I find the square of the distance and then I use sin & cos formulas from the math library to calculate back the "interpolated" point.


----------



## Big Bob (Apr 8, 2014)

Hi Paolo,

I'm glad you found a workaround but, the next library release will have all the inverse trig functions as well as Polar to Rectangular and vice versa. Maybe you can tidy things up a bit when V700 makes its appearance. :lol: 

In case you missed it, you may want to read this post also.

http://www.vi-control.net/forum/viewtopic.php?t=37863

Rejoice,

Bob


----------



## paoling (Apr 9, 2014)

Yes, I missed that, I was quite busy. Anyway thank you again Big Bob, when the new version of the library will be out I'll replace my custom and not-very-efficient way to calculate arc-tang and to revert from polar to coordinates with the cordic methods in the math library.


----------

