# Transform an entity a given distance along a given vector

**URL:** <https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506>\
**Category:** Ruby API\
**Created:** [October 19, 2015, 4:46pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506 "2015-10-19T16:46:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bckwdsmn](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bckwdsmn](https://forums.sketchup.com/u/bckwdsmn)\
**Post date:** [October 19, 2015, 4:46pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506/1 "2015-10-19T16:46:16Z")

</div>

Is there any way to move an entity a given distance along a vector  
what type of transformation would i use?

this is what i want to do but don’t know how to create the transformation  
trans = Geom::Transformation.new(point, vector, distance)

---

<div class="post-metadata">

**Author:** ![BruceYoung](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/bruceyoung/32/7523_2.png) [@BruceYoung](https://forums.sketchup.com/u/BruceYoung)\
**Post date:** [October 19, 2015, 5:03pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506/2 "2015-10-19T17:03:07Z")

</div>

The transformation you wrote (point, vector, distance) is not part of the API. The vector can include a length, or distance to displace, so the distance can be redundant. To move a relative amount, consider:

```
vector.length = distance
translate = Geom::Transformation.translation( vector )
entity.transform! translate

```

Group and components provide the “transform!” method, which “apply” the transform to the existing one (an affine transformation), moving it a relative amount.

If your position “point” is the current position of the group or component instance, then there would no additional operations. What is position “point”?

---

<div class="post-metadata">

**Author:** ![bckwdsmn](https://avatars.discourse-cdn.com/v4/letter/b/f08c70/32.png) [@bckwdsmn](https://forums.sketchup.com/u/bckwdsmn)\
**Post date:** [October 19, 2015, 5:22pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506/3 "2015-10-19T17:22:23Z")

</div>

I know that it is not a part of the API. it was only to illustrate what i am trying to accomplish. i actually didn’t meant to put the point in there. I want to move an entity a given distance in a given direction.

for example i have a square face that i position at the start of two input points. i have it rotate so the face.normal is parallel to the vector that the two input points make. from there i can pushpull it the distance between the two input points.

But before i extrude it i want to position the face at the desired quadrant that the user chooses in a inputbox  
hopefully the pictures will help

 ![](https://global.discourse-cdn.com/sketchup/original/2X/2/2c03535025cf7195143d12f69997e4f32f0ed503.jpg) ![](https://global.discourse-cdn.com/sketchup/original/2X/6/60bf2a726017f36bcff33db66bb8cd70aaef079f.jpg)

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [October 19, 2015, 5:30pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506/4 "2015-10-19T17:30:16Z")

</div>

The method @BruceYoung describes will work. You just have to calculate the required vector direction and length to move to the required quadrant. This may be easier if you break it down into two sequential translations along the two axes of the grid. Also, note that not all entities offer translate!. For primitive Edges and Faces you need to use their parent Entities collection’s transform\_entities method.

---

<div class="post-metadata">

**Author:** ![kimpastro](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/kimpastro/32/10571_2.png) [@kimpastro](https://forums.sketchup.com/u/kimpastro)\
**Post date:** [October 19, 2015, 6:03pm UTC](https://forums.sketchup.com/t/transform-an-entity-a-given-distance-along-a-given-vector/16506/5 "2015-10-19T18:03:07Z")

</div>

```
vec = entity.transformation.xaxis
vec.length = 12 #how much you wanna move
vec.reverse! # if needed to move to otherside
entity.transform! Geom::Transformation.translation(vec)

```

I think it’s the same problem as that:

> [@Transform\_entities not updating origin](http://forums.sketchup.com/t/transform-entities-not-updating-origin/14262):
>
> Hi guys, I’m working on a Tool that align elements, but when using entities#transform\_entities, the origin of the element doesn’t update. When perform a transform! over the element it updates (is this a rigid transformation?). Some example code: #element = best picked element.definition.entities.transform\_entities(Geom::Transformation.translation [0, 12, 0], element.definition.entities.to\_a) Then, when go to Ruby Console and perform the code below (with element selected), the origin came wi…
