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

lengthen or shorten vector

Participant ,
Oct 06, 2010 Oct 06, 2010

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
1.8K
Translate
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

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

Dan

Translate
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

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

Translate
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

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

Translate
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
LATEST

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

Mike

Translate
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