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

i want to bound circle within a box

New Here ,
Feb 01, 2025 Feb 01, 2025

src=wiggle(2,200);
boundary = [135,135]; // size of boundinglayer/2
clamp(src, value - boundary, value + boundary)
how i do this in dynamic way , means if shape layer is rectangle and i want when ever i change height and weidth and bound upadated , balls are bounded inside the inner box because the box have stroke. bound also updated with stroke changes ,how can  ido that , can anyone give me idea?

TOPICS
Expressions , How to
997
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 ,
Feb 01, 2025 Feb 01, 2025

highlight this value [135,135] and use expression pickwip and choose the rectangle size then add /2

src=wiggle(2,200);
boundary = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size / 2; // size of boundinglayer/2
clamp(src, value - boundary, value + boundary)

 

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 ,
Feb 01, 2025 Feb 01, 2025

To respect the rectangle stroke width, you need to subtract it from the rectangle size,
As the size data is a 2D vector [x,y] and the stroke width is a single dimension float value you can put it twice in a 2D vector then subtract it from the size
var temp = << pickwip to insert it's code >> ;
var strokeWidth = [temp.temp] ;

then do the subtraction in parentheses before deviding by 2 (size - strokeWidth) /2

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
New Here ,
Feb 01, 2025 Feb 01, 2025

also i need to minus circle redius also ?

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 ,
Feb 01, 2025 Feb 01, 2025

Sure, if you want to always keep the circle boundary inside the rectangle then you shoud subtract the circle size too.
(rectngleSize - circleSize - strokeWidth) / 2
but this assumes that the initial circle position is at the center of the rectangle, if not then you should calculate the clamp in a different way.

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 ,
Feb 01, 2025 Feb 01, 2025

it's usefull to control the wiggle parameters by slider controllers on a null layer to be able to change it once for all circles.

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
New Here ,
Feb 01, 2025 Feb 01, 2025

src=wiggle(2,200);
boundary = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Rectangle Path 1").size ; // size of boundinglayer/2
var t = thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Stroke 1").strokeWidth
var strokeWidth = [t,t] ;
r = content("Ellipse 1").content("Ellipse Path 1").size;
B = (boundary - strokeWidth - r )/2
clamp(src, value - B, value + B);
is this expression correct , with this my ball slightly excessed

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
New Here ,
Feb 01, 2025 Feb 01, 2025

is because of the result comes in decimal value ?

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 ,
Feb 01, 2025 Feb 01, 2025

does the circle have stroke?
does any of the layers has none 100% scale?

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 ,
Feb 01, 2025 Feb 01, 2025

it looks fine, but for good practice use ; at the end of each line

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 ,
Feb 01, 2025 Feb 01, 2025

both the rectangle and circle should have 100% scale

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
New Here ,
Feb 01, 2025 Feb 01, 2025

thanks it works

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 ,
Feb 01, 2025 Feb 01, 2025

Great! Happy Animating : )

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
New Here ,
Feb 01, 2025 Feb 01, 2025

but is it possible if cicle start from anywhere in the box and then behave like this , basically can we make this expression dynamic to there position ?

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 ,
Feb 01, 2025 Feb 01, 2025

sure, it just needs a different math
now you have the main idea, on a paper you can draw a line (as if it is the x axis) layout the boundaries and the circle and figure out the new formula 

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 ,
Feb 12, 2025 Feb 12, 2025
LATEST

@Indranil_Mondal9509 Did it work?

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