# Clamping of length

**URL:** <https://discourse.threejs.org/t/clamping-of-length/3431>\
**Category:** Resources\
**Tags:** geometry\
**Created:** [July 13, 2018, 3:30pm UTC](https://discourse.threejs.org/t/clamping-of-length/3431 "2018-07-13T15:30:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [July 13, 2018, 3:30pm UTC](https://discourse.threejs.org/t/clamping-of-length/3431/1 "2018-07-13T15:30:17Z")

</div>

Hi, community!  
I can’t say that I’ve discovered something unusual. I just want to show to beginners (like me 👶) the using of `.clampLength()` method of `THREE.Vector3()`. It allows to make an interesting effect: morphing the points from one formation to another, having the same constant speed for each vertex, when you know its start and end coordinates.

[https://jsfiddle.net/prisoner849/d9ar8j07/](https://jsfiddle.net/prisoner849/d9ar8j07/)

![Constant_speed_of_vertices_2](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/2/2b92ac07dbad2cee881e8e0b60ddf4d7d31cdf1f.gif)

P.S. Long ago, I’ve seen a very similar question on SO (though I couldn’t find it), and a guy seriously wanted to make the same effect, using Tween.js for each point 😵

P.P.S. I know it could be done with shaders, but this topic is for the beginners 🙂

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 13, 2018, 3:45pm UTC](https://discourse.threejs.org/t/clamping-of-length/3431/2 "2018-07-13T15:45:31Z")

</div>

> [@prisoner849](#):
>
> but this topic is for the beginners

In this case I suggest you try to avoid such statements in your code since they are hard to read.

```js
clampedDirLength.copy(morphV.dir).multiplyScalar(currentDuration * morph.speed).clampLength(0, morphV.dist);

```

Split them up into multiple lines and add some comments which explain what’s happening and why.

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [July 13, 2018, 6:05pm UTC](https://discourse.threejs.org/t/clamping-of-length/3431/3 "2018-07-13T18:05:17Z")

</div>

> [@Mugen87](#):
>
> Split them up into multiple lines and add some comments

Fair enough, Michael 🙂  
Done. The fiddle is updated.
