Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions position expression

  • position expression

    Posted by Ivan Semchuk on June 10, 2014 at 6:08 pm

    Hello,
    i’m trying to use exponential movement, but there appear error:
    invalid numeric error (divide by zero). But i can’t find if it’s really a “zero” problem:

    layer = "17";
    S=100/comp("MapLayers").layer(layer).scale[0];
    x1=640;
    y1=360;
    x2=x1+S*(comp("MapLayers").layer("1").position[0]-comp("MapLayers").layer("17").position[0]);
    y2=y1+S*(comp("MapLayers").layer("1").position[1]-comp("MapLayers").layer("17").position[1]);
    t1=1;
    t2=5;

    if (time <= t1){
    sx = x1;
    sy = y1;
    }else if (time > t1 && time < t2){
    t = time - t1;
    T = t2 - t1;
    kx = Math.log(x2/x1)/T;
    ky = Math.log(y2/y1)/T;
    sx = x1*Math.exp(kx*t);
    sy = y1*Math.exp(ky*t);
    }else{
    sx = x2;
    sy = y2;
    }
    [sx,sy]

    Ivan Semchuk replied 12 years, 3 months ago 3 Members · 12 Replies
  • 12 Replies
  • Dan Ebberts

    June 10, 2014 at 6:28 pm

    Just a guess, but one of your Math.exp() calculations may be overflowing. That will happen if kx*t or ky*t becomes greater than 710 or so.

    Dan

  • Ivan Semchuk

    June 10, 2014 at 6:30 pm

    Thank you for reply.
    Just fore note: added this expression to text layer.
    sx starting from 1st second to 5th gives “NaN” result.
    sy is OK always!

  • George Goodman

    June 10, 2014 at 6:37 pm

    the thing that is causing your error is this line:

    S=100/comp(“MapLayers”).layer(layer).scale[0];

    Just tack on a -1 so you don’t divide 100/00

    I’m not exactly sure what you’re trying to do with it, but I hope that helps.

    S=100/comp("MapLayers").layer(layer).scale[0] - 1;

    “|_ (°_0) _|”

    Sincerely,

    George

    http://www.vimeo.com/georgegoodman
    http://www.linkedin.com/in/georgefranklingoodman

  • Ivan Semchuk

    June 10, 2014 at 6:41 pm

    Thank you. But it doesn’t work(
    I understood that “sy” works, but not “sx”!
    So I separated coorinates to see less code)
    Still no guess what is vrong with divide by zero!

    layer = "17";
    S=100/comp("MapLayers").layer(layer).scale[0];
    x1=640;
    x2=x1+S*(comp("MapLayers").layer("1").position[0]-comp("MapLayers").layer(layer).position[0]);
    t1=1;
    t2=5;

    if (time <= t1){
    sx = x1;
    }else if (time > t1 && time < t2){
    t = time - t1;
    T = t2 - t1;
    kx = Math.log(x2/x1)/T;
    sx = x1*Math.exp(kx*t);
    }else{
    sx = x2;
    }
    sx

  • George Goodman

    June 10, 2014 at 6:43 pm

    I didn’t get the error after I tacked on the -1, however, you didn’t define lt in the variables so I removed it when I tried it.

    “|_ (°_0) _|”

    Sincerely,

    George

    http://www.vimeo.com/georgegoodman
    http://www.linkedin.com/in/georgefranklingoodman

  • Ivan Semchuk

    June 10, 2014 at 6:46 pm

    Here is the code with clear variables: still no luck!

    S=65536;
    x1=640;
    x2=-3428578.8
    t1=1;
    t2=5;

    if (time <= t1){
    sx = x1;
    }else if (time > t1 && time < t2){
    t = time - t1;
    T = t2 - t1;
    kx = Math.log(x2/x1)/T;
    sx = x1*Math.exp(kx*t);
    }else{
    sx = x2;
    }
    sx

  • George Goodman

    June 10, 2014 at 6:49 pm

    Sorry, forgot I did a little other clean up. See if this does what you want.

    layer = "17";
    S=100/comp("MapLayers").layer(layer).scale[0]-1;
    x1=640;
    y1=360;
    x2=x1+S*(comp("MapLayers").layer("1").position[0]-comp("MapLayers").layer("17").position[0]);
    y2=y1+S*(comp("MapLayers").layer("1").position[1]-comp("MapLayers").layer("17").position[1]);
    t1=1;
    t2=5;

    if (time == t1){
    sx = x1;
    sy = y1;
    }else if (time > t1 && time == t2){
    t = time - t1;
    T = t2 - t1;
    kx = Math.log(x2/x1)/T;
    ky = Math.log(y2/y1)/T;
    sx = x1*Math.exp(kx*t);
    sy = y1*Math.exp(ky*t);
    }else{
    sx = x2;
    sy = y2;
    }
    [sx,sy]

    “|_ (°_0) _|”

    Sincerely,

    George

    http://www.vimeo.com/georgegoodman
    http://www.linkedin.com/in/georgefranklingoodman

  • Ivan Semchuk

    June 10, 2014 at 6:53 pm

    Tried it, however “sx” shows -3428526.47427368.
    And only in 1st second it show 640. Strange…
    Did you try with a simple variables I sent earlier?

  • George Goodman

    June 10, 2014 at 6:54 pm

    No sorry, don’t think I can be of help on this one. I think I jumped out of my league here.

    Maybe upload a project file and give a little more detail of what you’re trying to do. Someone else may be able to jump in.

    “|_ (°_0) _|”

    Sincerely,

    George

    http://www.vimeo.com/georgegoodman
    http://www.linkedin.com/in/georgefranklingoodman

  • Ivan Semchuk

    June 10, 2014 at 7:00 pm

    Thank you anway! Still working on it.
    I’m trying to match a scale of a map with its position.
    So i have 17 layers. Scale works perfect. Y coorinates aswell. Just X coorinate fdoes not work.
    So I have this code that can be just pasted into TEXT source to see that something is wrong.
    The code doe not refering anything so the project file does not need to bee uploaded.

    S=65536;
    x1=640;
    x2=-3428578.8
    t1=1;
    t2=5;

    if (time <= t1){
    sx = x1;
    }else if (time > t1 && time < t2){
    t = time - t1;
    T = t2 - t1;
    kx = Math.log(x2/x1)/T;
    sx = x1*Math.exp(kx*t);
    }else{
    sx = x2;
    }
    sx

Page 1 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy