# Applying transformation matrices to vectors

**URL:** <https://openrndr.discourse.group/t/applying-transformation-matrices-to-vectors/701>\
**Category:** Tutorials\
**Created:** [November 10, 2024, 4:14pm UTC](https://openrndr.discourse.group/t/applying-transformation-matrices-to-vectors/701 "2024-11-10T16:14:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abe](https://yyz2.discourse-cdn.com/free1/user_avatar/openrndr.discourse.group/abe/32/700_2.png) [@abe](https://openrndr.discourse.group/u/abe)\
**Post date:** [November 10, 2024, 4:14pm UTC](https://openrndr.discourse.group/t/applying-transformation-matrices-to-vectors/701/1 "2024-11-10T16:14:56Z")

</div>

An issue I fell into recently: I was creating transformation matrices and when applying them to vectors, I was getting `Vector4(0.0, 0.0, 0.0, 0.0)` no matter how I constructed those matrices.

It turns out I was using `Vector4.ZERO` as a starting point (a vector with four zeros). My intention was to start at the origin. But the last zero, the `w` component, is used as a multiplier. If you multiply any numbers by zero, you know what we get.

What I should have done instead was to use `Vector4.UNIT_W` instead: `(0.0, 0.0, 0.0, 1.0)`, representing a point located at `(0.0, 0.0, 0.0)` and the scaling factor being `1.0`.

![vtt](https://global.discourse-cdn.com/free1/uploads/openrndr/original/1X/8db9435a8c0d116db4027ff534797ad94a331d79.webp)

Maybe it’s obvious, but if not, now you know 🙂

```kotlin
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.ffmpeg.ScreenRecorder
import org.openrndr.math.Vector3
import org.openrndr.math.transforms.transform

```

```kotlin
fun main() = application {
    program {
        extend(ScreenRecorder()) { maximumDuration = 10.0 }
        extend {
            drawer.clear(ColorRGBa.WHITE)
            repeat(6) { x ->
                repeat(6) { y ->
                    val tr = transform {
                        translate(x * 100.0 + 20.0, y * 60.0 + 50.0)
                        rotate(x * 60 + y * 15.0 + seconds * 36.0)
                        translate(50.0, 0.0)
                    }
                    //val p = tr * Vector4.ZERO // BAD
                    val p = tr * Vector4.UNIT_W // GOOD

                    drawer.fill = ColorRGBa.PINK
                    drawer.circle(p.xy, 5.0)
                }
            }
        }
    }
}

```

If you want to apply transformations to any Vector3 (even if they are not at the origin), do it like this: `val p = tr * myVec3.xyz1`.

And with Vector2: `val p = tr * myVec2.xy01`.
