# How to apply one-sided (directional) scaling to a matrix?

**URL:** <https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562>\
**Category:** HOOPS Visualize Web\
**Tags:** code, knowledge-base, how-to\
**Created:** [April 15, 2025, 9:11am UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562 "2025-04-15T09:11:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cad-developer](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@cad-developer](https://forum.techsoft3d.com/u/cad-developer)\
**Post date:** [April 15, 2025, 9:11am UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562/1 "2025-04-15T09:11:49Z")

</div>

I’m using `matrix.setScaleComponent` (directly used in below reference url) to scale a matrix along a specific axis (e.g., X, Y, or Z). However, the scaling occurs symmetrically in both directions (e.g., both +X and -X). I want to apply the scale only in one direction — for instance, only along the +X axis. Is there a way to achieve directional scaling (only +X, +Y, or +Z) using this method or another approach?

Please refer - [Scale Handles Operator](https://forum.techsoft3d.com/t/scale-handles-operator/530)  
using this I am trying to scale in one direction.

---

<div class="post-metadata">

**Author:** ![guillaume.robichaud](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@guillaume.robichaud](https://forum.techsoft3d.com/u/guillaume.robichaud)\
**Post date:** [April 16, 2025, 8:34pm UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562/3 "2025-04-16T20:34:47Z")

</div>

To scale in X+ only:

1. Take your initial matrix:  
`const mat = model.getNodeMatrix(id)`

2. Create a translation where you want to scale from (if your part’s origin is in the middle, then translate half the width)  
`const transMat = new Communicator.Matrix().setTranslationComponent(size_x / 2, 0, 0)`

3. Create your scaling:  
`const scaleMat = new Communicator.Matrix().setScaleComponent(scale_x, 1, 1)`

4. Then undo the translation:  
`const transInvMat = Communicator.Matrix.inverse(transMat)`

5. Then it’s just a matter of compounding all the transformations together:

```auto
mat = Communicator.Matrix.multiply(mat, transMat)
mat = Communicator.Matrix.multiply(mat, scaleMat)
mat = Communicator.Matrix.multiply(mat, transInvMat)
model.setNodeMatrix(id, mat)

```

---

<div class="post-metadata">

**Author:** ![cad-developer](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@cad-developer](https://forum.techsoft3d.com/u/cad-developer)\
**Post date:** [April 17, 2025, 6:28am UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562/4 "2025-04-17T06:28:52Z")

</div>

> [@guillaume.robichaud](#):
>
> const transInvMat = Communicator.Matrix.inverse(transMat)

What if I want to scale in -X direction now? Means I am working on resize functionality of polygon using its six faces to resize using handles.

---

<div class="post-metadata">

**Author:** ![guillaume.robichaud](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@guillaume.robichaud](https://forum.techsoft3d.com/u/guillaume.robichaud)\
**Post date:** [April 17, 2025, 6:53pm UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562/5 "2025-04-17T18:53:46Z")

</div>

It’s always the same pattern, define what your anchor point is, translate your part there before scaling or rotating and then undo your translation.

So for X-, again, this is assuming your part’s origin is in the center:  
transMat = new Communicator.Matrix().setTranslationComponent(-size\_x / 2, 0, 0)

so on so forth:  
Y+ setTranslationComponent(0, size\_y / 2, 0)  
Y- setTranslationComponent(0, -size\_y / 2, 0)  
Z+ setTranslationComponent(0, 0, size\_z / 2)  
Z- setTranslationComponent(0, 0, -size\_z / 2)

---

<div class="post-metadata">

**Author:** ![guillaume.robichaud](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@guillaume.robichaud](https://forum.techsoft3d.com/u/guillaume.robichaud)\
**Post date:** [April 17, 2025, 6:55pm UTC](https://forum.techsoft3d.com/t/how-to-apply-one-sided-directional-scaling-to-a-matrix/4562/6 "2025-04-17T18:55:08Z")

</div>

![Screenshot from 2025-04-16 16-38-45](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/0/00b9f58b0a5b2fa61f2aa0aa76ba3b3f4f9a7a2c.png)
