FORUMS: list search recent posts

# Moving Null into a circle (clamp expression)

FAQ   •   VIEW ALL
 Moving Null into a circle (clamp expression) on Sep 24, 2015 at 6:44:45 pmLast Edited By Mysteropodes Drouin on Sep 24, 2015 at 6:58:29 pm

Hi everybody,

I'm using Clamp expression for stop my controller (Null), it's useful for a character rig.
But it's always moving my null into a square or rectangle.
Is there a way to moving my null into a circle?

I think i have to use the cos and sin but i don't know how to mix clamp with that.

Sorry for my bad english and thank you a lot

```x= clamp(value[0],100,200); y= clamp(value[1],100,200); [x,y]```

 Re: Moving Null into a circle (clamp expression)on Sep 24, 2015 at 8:55:22 pm

Probably not the neatest code for the purpose, but this does it:

```origin_x=150, origin_y=150; radius = 50; x0=value[0]-origin_x; y0=value[1]-origin_y; distance0 = Math.sqrt(x0*x0+y0*y0); distance = Math.min(distance0,radius); if (distance0>radius){ distance_mult = distance/distance0; }else{ distance_mult = 1 } x=origin_x+distance_mult*x0; y=origin_y+distance_mult*y0; [x,y]```

set origin_x and origin_y to the center point of the circle and radius to the radius of the constraint area.