ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

control path length using expressions

COW Forums : Color Grading

VIEW ALL   •   PRINT
Tom Morton
control path length using expressions
on Aug 16, 2018 at 10:20:29 am

Hello, I'm a bit new to expressions (yeah same old story, beginners trying their luck!) I can work fine with expressions, but I want to control the length of a path. I can control anchor point, position, etc easily, but not sure how path length is selected in an expression? Is it a length or does a path run between two points?

Cheers, Tom


Return to posts index

Dan Ebberts
Re: control path length using expressions
on Aug 16, 2018 at 4:15:00 pm

You have to redefine the path, using createPath(v,iT,oT,c), specifying matrices of vertices, in tangents, and out tangents, as well as a boolean flag specifying whether the path is closed or not.

Dan



Return to posts index

Tom Morton
Re: control path length using expressions
on Aug 21, 2018 at 7:46:31 am

Thanks Dan, that sounds like what I'm looking for. Are the any good tutorials / explanations online showing how to format that expression correctly? I can't use trim paths because the length of the path will change and I can't get it accurate enough.

Regards,

Tom Morton | Digital Everything

If it can be automated, let the computer take the load. Creativity leads creativity.


Return to posts index


Andy Engelkemier
Re: control path length using expressions
on Sep 5, 2019 at 8:03:33 pm

Ah, yikes. Is there an example of this?

My issue is I'm animating several lines with different length. The "speed" all looks the same because it's just moving the trim path, but that's based on a percentage.

It's a real shame that AE didn't include a path length variable so you could use that in expressions without having to create the complicated math every time. At least, that's what I'm finding.

So for me, if I half circle paths and one length is half the other, when I go to animate the trim path, I'd want one finishing in half the time as the other. I was just going to do it manually based on the path length, but I couldn't find that.

So my solution? Ha, copy and paste the path into illustrator. Select a path and open up the Document Info window. Change, via the hamburger menu, to objects, and yay, it shows you the path length.

So I wrote those down, and that gave me the percentage to slow each animation down so all the trim animations were moving at the same rate.

So Adobe HAS math to calculate that already. It would just be lovely if they had it as an object you can call on within expressions.


Return to posts index

Kalleheikki Kannisto
Re: control path length using expressions
on Aug 18, 2018 at 8:06:30 am

If you just need to draw a part of the path, you can use trim paths to limit the stroke to a percentage of the path.

Kalleheikki Kannisto
Senior Graphic Designer


Return to posts index

Andy Engelkemier
Re: control path length using expressions
on Sep 6, 2019 at 12:25:11 pm

Yes, I'm aware that you can use trim paths. But a percentage of two different paths of different lengths cause the "draw" to go at different speeds.
So if you want the path to draw on at the same rate, you have to calculate the path length because you have to adjust the start and finish times based on the path length.

In case that's Still not clear.
I have two paths. One is 3000px long, the other is 6000px long. I start their animation both at 00;00;00. I would like them to go at the same speed, only, I don't know how long they are (because AE doesn't tell me). So when I start and finish them both at the same time, the path that is twice as long appears to animate on twice as fast. Instead, I would like to have the 3000px path move at the same rate, and finish in half the time.

So I'm copying and pasting these paths into Illustrator to find out the lengths, then adjusting the keys based on the percentage they are different. I have quite a few to do, so it's a bit of a pain. I'd rather be able to keep things in AE with expressions.


Return to posts index


Dan Ebberts
Re: control path length using expressions
on Sep 6, 2019 at 3:57:50 pm

Just a thought--one possibility would be to use pointOnPath() to get the approximate distance along a tiny portion of each path so you can compare them:

d1 = length(path1.pointOnPath(.001,time),path1.pointOnPath(0,time));
d2 = length(path2.pointOnPath(.001,time),path2.pointOnPath(0,time));

Then the ratio of d1 to d2 should give you what you need to control the trim paths, maybe?


Dan



Return to posts index

Andy Engelkemier
Re: control path length using expressions
on Sep 6, 2019 at 5:31:17 pm

So I Think this works? But I'd like to double check on my understanding on what is going on. Too bad they don't just give you access to the arc length they refer to in the help file.

the PointOnPath command is giving you a point at a specific percentage of the total arc length at the current time (being only relevant if the length of the path changes over time?).
So you are getting a VERY small sample of the length based on percentage in order to solve for the path being not straight.

So it looks like you're getting the length of 2 points on the path, at 0%, and .001%.


I plugged that into a slider control on two paths, and that does match the percentages that I changed it based on my total length measurements in illustrator, so that will definitely work. I just wanted to be sure I understood correctly.

Length will only give you the distance between two points in a straight line, correct? I assume that's why you used an incredibly small distance.


Return to posts index

Dan Ebberts
Re: control path length using expressions
on Sep 6, 2019 at 5:41:22 pm

That's it exactly.

Dan



Return to posts index


Andy Engelkemier
Re: control path length using expressions
on Sep 6, 2019 at 5:45:55 pm

OH! I just noticed....

d1 length was 3.71
d2 length was 1.39

actual lengths were 3710 and 1391

so other than cases when your path begins with an Extreme, very small arc, then continues on, this should be almost exactly the the correct length in pixels, if you multiply by 1000.

Now if I can figure out how to adjust the key based on that ratio...lol
I'm still learning with expressions, which is why I asked for clarification. I hate Thinking I know something (when it's actually wrong)

I just moved the end key based on the ratio I had.

For an expression, my guess is setting one key at zero, and that's it. Then do the rest through expressions. But I've always failed miserably when it comes to expressions based on time. (also I'm bad at math)


Return to posts index

Dan Ebberts
Re: control path length using expressions
on Sep 6, 2019 at 5:55:39 pm

My guess is that apps that give you the path length do it by adding up a bunch of tiny straight line chunks to approximate the length along the curve. The smaller the pieces, the more accurate the result, but the longer it takes.


Dan



Return to posts index

Alex Printz
Re: control path length using expressions
on Sep 6, 2019 at 8:49:54 pm

I have built a trim paths expression to do this in the past.

IIRC, you need to make a slider to set the 'full' length, then create a loop that measures the distances between pointOnPaths on a spline and adds them together, compares that to the 'full' length, and if the current spline is measured longer than that trim that percentage. I used a 2nd slider to set the number of points to compare (I think I liked around 12 or so, not too many to bog the system, not too few to look choppy)

It worked well for what I needed to do (swinging rope I think?)

Alex Printz
Mograph Designer


Return to posts index

VIEW ALL   •   PRINT
© 2019 CreativeCOW.net All Rights Reserved
[TOP]