Activity › Forums › Adobe After Effects Expressions › 2d position to sphere
-
2d position to sphere
Posted by Peter Menich on March 31, 2008 at 10:22 pmHi all,
I’m doing a world map with country names using CC Sphere. The problem I’m having is that the most northern and southern countries names get distorted.
I’ve got all the country names as separate 3D layers in a flat 2:1 comp.
So what I want to do is use there position value (through trig) to reposition them into a sphere by using a control null with slider to set radius.
I’ve had some success and learned a shed load. but still not gotten to my goal!
I managed to get the position values to drive rotation values ok, then set my position to the sphere centre and link the anchor z value to the radius slider.
But to further complicate matters I have a target layer which moves about and causes the country names to scale up when they get closer to the target. So the previous method doesn’t work.
So I’m currently exploring using the LookAt function to set the orientation toward a null placed at the spheres centre. I’ve now gotten to the part where I have to reformat the position values to stick to the sphere, again using a control null slider for radius.
But its now gone 11 at night and my noodle has turned to mush. So in the hope that some guru can push me in the right direction I thought I’d drop this here before I retire!
Geert Schaap replied 5 years, 8 months ago 6 Members · 19 Replies -
19 Replies
-
Peter Menich
April 1, 2008 at 12:00 pmOK, so no ones biting. I’ll share where I’m up to to see if anyone gets turned on…
https://www.zedzero.co.uk/2DtoSphere_Project.aep.zip
Basically at the moment I have 2DtoCylinder rather than 2DtoSphere!
I need to get my noggin around somehow adding the transformations so when the object moves away from the ‘equator’ it moves inwards.
Any ideas anyone?!
-
Darby Edelen
April 1, 2008 at 3:11 pmDan has a site with a lot of awesome expression information available. Among the troves there is this:
https://www.motionscript.com/mastering-expressions/random-sphere.html
Which takes two angles to determine the position on a sphere. Hopefully this will help, although it has a lot of extraneous information (for your purposes).
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Peter Menich
April 1, 2008 at 6:45 pmCheers Darby,
I’m very familiar with Dans site and have plundered it often! But I totally missed this one.
I’ve had a look at it, and it does what I want to do in terms of placement on a sphere (without the random motion)…but I gotta be honest…I don’t get it :O(
I fear I may have reached the limit of my intelligence.
If anyone (Dan) is out there and can explain this to me is simple terms I promise to share the project with everyone when its done. (creep, creep, grovel, grovel)
-
Dan Ebberts
April 1, 2008 at 8:16 pmOne of the ideas in that article is that you can calculate the x,y, and z coordinates of a point on a sphere if you know the radius (r), the angle (theta) around the y axis (between 0 to 2*pi), and the angle (phi) from the z axis (between 0 and pi).
Then:
x = r*cos(theta)*sin(phi)
y = r*sin(theta)*sin(phi)
z = r*cos(phi)It’s not clear to me that the radius and the two angles are the variables you’re working with, so I’m not sure if that helps you or not.
Dan
-
Peter Menich
April 1, 2008 at 9:16 pmHey Dan,
Thanks for replying.
I’ve been kinda clutching at straws with which variables I’m using.
I think what I’m not getting is how to get the 2 angles from my x,y coordinates.
I bet its one of those real DOH! moments when it finally clicks (or someone puts me out of my misery).
I just seem to be going around in circles trying different things and getting more and more confused.
-
Dan Ebberts
April 1, 2008 at 9:27 pmI’d guess you would just run it backwards:
phi = Math.acos(z/r);
theta = Math.acos(x/(r*Math.sin(phi));Then convert the angles from radians to degrees.
Dan
-
Darby Edelen
April 1, 2008 at 10:18 pmThe image at the top gives you most of the useful information in this case. Here’s his expression boiled down to what you need:
r = 50; //radius of sphere
phi = degreesToRadians(45); //angle from z-axis to point on sphere
theta = degreesToRadians(45); //rotation around z-axis to point on spheresinPhi = Math.sin(phi);
x = r*Math.cos(theta)*sinPhi;
y = r*Math.sin(theta)*sinPhi;
z = r*Math.cos(phi);offset = [x,y,z];
center = toWorld(anchorPoint);center + offset;
You can link the phi and theta values to angle expression controls and the radius to a slider control for easier control of the positioning.
The details of the trig functions are probably the most confusing part, but the image on the page should help clarify that somewhat.
FYI the symbol for theta has the horizontal line running through it, and the symbol for phi has the vertical line.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Peter Menich
April 2, 2008 at 1:24 pmHey Darby and Dan, (is that a sitcom or what?)
Cheers for sticking with me on this. Unfortunately it’s still not working.
I think the trouble I’m having is the differences in syntax that I keep getting with the examples you’ve given me, and the axis in my comp is different from the one on Dans site (my y axis points up).
So I’ve tried multiple methods of +/- 90deg here and there and it never works out right – I feel like I’m chasing my tail a bit.
Here’s a link to my project where its at…
https://www.zedzero.co.uk/2DtoSphere_V3_Project_folder.zip
At the top you’ll see a blue solid which is my test object, once I have it working on this I’ll copy and paste the expression to all the country name layers below.
Its so nearly there I can taste it!
Here’s my code for the position parameter…
div = thisComp.width/360;//<---This variable divides my comp width by 360 to give me the value I need to divide my x and y values to get the angle, in the case 5400/360=15 (I've added this to make the code flexible for different comp sizes) r = thisComp.layer(“target”).effect(“radius”)(“Slider”);//<---This variable sets my radius, linked to a slider on a null, in this case 900 xRot = degreesToRadians(value[0]/div);//<---This is my x position divided by 'div' (15) to get my angle around the y axis, then converted to radians. zRot = degreesToRadians(value[1]/div);//<---This is my y position divided by 'div' (15) to get my angle around the x axis (or from the z axis), then converted to radians. theta = xRot;//<---This is your theta variable, which I'm essentially putting my xRot variable into, I've done this because I've been adding +/- 90deg or *-1 to try and get it working phi = zRot;//<---This is your phi variable, which I'm essentially putting my zRot variable into, I've done this because I've been adding +/- 90deg or *-1 to try and get it working sinPhi = Math.cos(phi);//<---This bit I don't understand! //This following bit I've tried to follow on the various examples, but have struggled because the syntax keeps changing. I've also swapped the y and z around because my axis differs from Dans illustration. x = r*Math.sin(phi)*Math.cos(theta)
y = r*Math.cos(phi)
z = r*Math.sin(phi)*Math.sin(theta)//This bit I get – stick it in the centre!
center = thisComp.layer(“target”).position;
center + [x, y, z]
What I need is for the blue square to sit on the equator, dead centre on the camera side (over Africa) when the position is 2700, 1350, 0.
If you change the position to 1350, 1350, 0 it will swing round 90deg along the equator toward South America.
If you change the position to 2700, 675, 0 it will swing up toward Europe.
If you change the position to 2700, 2025, 0 it will swing down toward South Africa.
If you change the position to 5400, 1350, 0 it will go right around to the other side of the globe on the equator.
If you change the position to 4050, 675, 0 it will move around to somewhere around Mongolia!All my country names have an x and y value, with 0 for z. The idea is when this expression is pasted into them all they’ll wrap around the globe in the correct positions.
I do have a budget to pay for someone to solve this for me, as I’m clearly having a mental block.
-
Darby Edelen
April 2, 2008 at 3:44 pmI’m sorry, I had abandoned the idea of using a 2D position to get the position on the sphere. Personally I thought it would be much easier to just scrub the angle values until the text lined up properly then parent to a Null to rotate with the sphere (if necessary).
I’ll have to look at your project later today to see if I can help figure out the 2D position quandary.
Darby Edelen
Designer
Left Coast Digital
Santa Cruz, CA -
Dan Ebberts
April 2, 2008 at 4:20 pmI think the trick is to map your x position to a 360 degree range that makes sense to After Effects and map your y position to a 180 degree range. I think it will look something like this:
xRot = degreesToRadians(linear(value[0],0,thisComp.width,270,-90));
zRot = degreesToRadians(linear(value[1],0,thisComp.height,-90,90);Or, maybe the other way around. 😉
Dan
Reply to this Discussion! Login or Sign Up