<p>So I have a matrix:</p>

<pre><code>Matrix4f Mbsp = Matrix4f(Vector4f(1.0, 4.0, 1.0, 0.0)
            , Vector4f(-3.0, 0.0, 3.0, 0.0)
            , Vector4f(3.0, -6.0, 3.0, 0.0)
            , Vector4f(-1.0, 3.0, -3.0, 1.0), true);
</code></pre>

<p>and I'm doing a scalar multiplication to it, e.g.:</p>

<pre><code>Mbsp = (1.0/6.0)*Mbsp;
</code></pre>

<p>One would now expect Mbsp to be</p>

<p>$$\begin{array} &amp;1/6&amp;-1/2&amp;1/2&amp;-1/6\\2/3&amp;0&amp;-1&amp;1/2\\1/6&amp;1/2&amp;1/2&amp;-1/2\\ 0&amp;0&amp;0&amp;1/6 \end{array}$$</p>

<p>However Mbsp now is:</p>

<p>$$\begin{array} &amp;1.0&amp;1.4901161e-008&amp;1.4901161e-008&amp;0\\1.0&amp;1.4901161e-008&amp;1.4901161e-008&amp;0\\1.0&amp;1.4901161e-008&amp;1.4901161e-008&amp;0&amp;\\ 1.0&amp;1.4901161e-008&amp;1.4901161e-008&amp;0 \end{array}$$</p>

<p>Similarly, doing (using the original Mbsp): </p>

<pre><code>Mbsp = 2.0*Mbsp;
</code></pre>

<p>Gives</p>

<p>$$\begin{array} &amp;12&amp;0&amp;0&amp;0\\12&amp;0&amp;0&amp;0\\12&amp;0&amp;0&amp;0\\ 12&amp;0&amp;0&amp;0 \end{array}$$</p>

<p>What's wrong?</p>

CC BY-SA 3.0
2017-02-09T11:03:04.430Z
which matrix lib?
ratchet freak
CC BY-SA 3.0
2017-02-09T11:05:49.667Z
@ratchetfreak vecmath
mavavilj
CC BY-SA 3.0
2017-02-11T00:19:18.350Z
Have you printed out the original matrix to ensure its constructed OK? Can you step through code to check the scalar multiplication operator is being called and verify that a temporary matrix/vector isn't being constructed? Can you post a link to this vecmath library?
PeteUK
<opengl><bezier-curve><matrix>
Scalar multiplication in vecmath on Matrix4f results in strange values
mavavilj
# Scalar multiplication in vecmath on Matrix4f results in strange values

(Asked by: username_0 on 2017-02-09)

So I have a matrix:

```
Matrix4f Mbsp = Matrix4f(Vector4f(1.0, 4.0, 1.0, 0.0)
            , Vector4f(-3.0, 0.0, 3.0, 0.0)
            , Vector4f(3.0, -6.0, 3.0, 0.0)
            , Vector4f(-1.0, 3.0, -3.0, 1.0), true);

```

and I'm doing a scalar multiplication to it, e.g.:

```
Mbsp = (1.0/6.0)*Mbsp;

```

One would now expect Mbsp to be

$$\begin{array} &1/6&-1/2&1/2&-1/6\\2/3&0&-1&1/2\\1/6&1/2&1/2&-1/2\\ 0&0&0&1/6 \end{array}$$

However Mbsp now is:

$$\begin{array} &1.0&1.4901161e-008&1.4901161e-008&0\\1.0&1.4901161e-008&1.4901161e-008&0\\1.0&1.4901161e-008&1.4901161e-008&0&\\ 1.0&1.4901161e-008&1.4901161e-008&0 \end{array}$$

Similarly, doing (using the original Mbsp):

```
Mbsp = 2.0*Mbsp;

```

Gives

$$\begin{array} &12&0&0&0\\12&0&0&0\\12&0&0&0\\ 12&0&0&0 \end{array}$$

What's wrong?

**Tags:** opengl, bezier-curve, matrix

> **Comments:**
> **username_1**: which matrix lib?  
> **username_0**: @username_1 vecmath  
> **username_2**: Have you printed out the original matrix to ensure its constructed OK? Can you step through code to check the scalar multiplication operator is being called and verify that a temporary matrix/vector isn't being constructed? Can you post a link to this vecmath library?  

---

## 0 answers

