• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

lengthen or shorten vector

Participant ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

this may seem trivial, but vector mathematics is not my strong suit.

if I have a vector between point A and point B, how do I shorten it (or lengthen it), but maintian a center point between A and B, like this

  A------------B  old vector

  A  --------  B new vector or

--A------------B-- another new vector

TOPICS
Expressions

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

Vectors don't really have a position, just length and direction. What are you trying to do exactly?

Dan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

Hey Dan,

I have this expression that disperses layers in a comp between 2 nulls; so the first layer will get position of null 1, the last layer gets position of null 2 and all layers in between get evenly dispersed along a line between them.

what i am trying to figure out is a way to lengthen or shorten the line between the nulls.  the position expression on each of the layers looks like this (the 2 nulls are the last 2 layers in the comp)

n = thisComp.numLayers;
v1 = thisComp.layer(n-1).position;
v2 = thisComp.layer(n).position;
if (index == 1){
  v1
}else if (index == n-2){
  v2
}else{
  v1 + (v2 - v1)*((index-1)/(n-3))
}

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

This should do it:


offset = 25; // positive makes line longer

n = thisComp.numLayers;
v1 = thisComp.layer(n-1).position;
v2 = thisComp.layer(n).position;
v = normalize(v2 - v1)*offset;
v2 += v;
v1 -= v;
if (index == 1){
  v1
}else if (index == n-2){
  v2
}else{
  v1 + (v2 - v1)*((index-1)/(n-3))
}

Dan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 06, 2010 Oct 06, 2010

Copy link to clipboard

Copied

LATEST

Awesome! thanks Dan, this is exactly what I needed.

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines