Skip to main content
Community Expert
October 1, 2022
Answered

How do I move a layer at a specific angle using an expression

  • October 1, 2022
  • 3 replies
  • 352 views

I've been fiddling with this one for several hours, and it's time to humbly ask for help. I know the basics; if you know the length of the opposite side of a right triangle and the angle, you can calculate the adjacent side's value. If I have a center layer and an Expression Control slider for the hypotenuse length or radius of a circle from the center and have an Angle Control for angle, I should be able to calculate the X and Y values for the target layer. The sin and cos of the angle time the hypotenuse don't work. I'm stuck. Any suggestions would be appreciated. I can't even get the first 90º to work. If anyone knows, it's Dan Ebberts.

This topic has been closed for replies.
Correct answer Rick Gerard

Thank you Dan Ebberts.  I figured it out. Once I converted the angle to radians, everything worked fine. Here's the final expression:

 

h = effect("h")("Slider");
a = effect("a")("Angle") - 90;
angle = degreesToRadians(a);
x = h * Math.cos(angle);
y = h * Math.sin(angle);
c = thisComp.layer("Center").position;
[x, y]

 

This was the research part of a much larger project that involves distributing a bunch of 3D layers in a sphere. It's a complicated model of a galaxy. I only have angle and distance data to work with. 

 

Must have been tired. I did not think about the degrees to radians modifier until I quit for the night. As soon as that was in there, I have all I need to make a bunch of planets orbit around a star in orbits that are not symmetrical. 

3 replies

Rick GerardCommunity ExpertAuthorCorrect answer
Community Expert
October 1, 2022

Thank you Dan Ebberts.  I figured it out. Once I converted the angle to radians, everything worked fine. Here's the final expression:

 

h = effect("h")("Slider");
a = effect("a")("Angle") - 90;
angle = degreesToRadians(a);
x = h * Math.cos(angle);
y = h * Math.sin(angle);
c = thisComp.layer("Center").position;
[x, y]

 

This was the research part of a much larger project that involves distributing a bunch of 3D layers in a sphere. It's a complicated model of a galaxy. I only have angle and distance data to work with. 

 

Must have been tired. I did not think about the degrees to radians modifier until I quit for the night. As soon as that was in there, I have all I need to make a bunch of planets orbit around a star in orbits that are not symmetrical. 

Dan Ebberts
Community Expert
Community Expert
October 1, 2022

Rick,

I'm having trouble picturing which point you're trying to calculate. Do you maybe just need to convert your angle from the degrees of your angle control to radians required by Math.sin() and Math.cos()? If that's not it, just post a sketch and we'll get it.

Mylenium
Legend
October 1, 2022

Law of cosines.

 

https://en.wikipedia.org/wiki/Law_of_cosines

 

You calculate the second angle (the third will always be 90, anyway) and then can calculate the lengths of all sides.

 

Mylenium