Vector scaling

Scaling a vector by a real number changes the magnitude (length) of the vector, but not the direction. A vector can be negated if scaled by \(-1\). A negative vector \((-\vec{A})\) has the same magnitude as the original vector \((\vec{A})\), but points in the opposing direction.To scale a vector by a scalar, multiply every component of the vector by the scalar:

$$ \vec{A}s = (A_0 s, A_1 s ... A_n s) $$

In the example below, vector \( \vec{A} \) is shown as a blue arrow. The scalar \(s\) can be set with the green slider. The orange arrow is the result of scaling \(\vec{A}\) by \(s\)

Canvas support required

Implementing scaling in code is trivial:

vec2 Scale(vec2 a, float s) {
    return vec2(a.x * s, a.y * s);
}

vec3 Scale(vec3 a, float s) {
    return vec3(a.x * s, a.y * s, a.z * s);
}

vec4 Scale(vec4 a, float s) {
    return vec4(a.x * s, a.y * s, a.z * s, a.w * s);
}

Vector multiply (Non uniform scale)

Multiplying two vectors together results in a non-uniform scale operation. When multiplying two vectors, just multiply like components. For example, when multiplying \(\vec{A} * \vec{B}\) each component of \(\vec{A}\) is scaled by the coresponding component of \(\vec{B}\).

$$ \vec{A} * \vec{B} = (A_0 B_0, A_1 B_1 ... A_n B_n) $$

Again, implementing this in code should be fairly trivial:

vec2 Mul(vec2 a, vec2 b) {
    return vec2(a.x * b.x, a.y * b.y);
}

vec3 Mul(vec3 a, vec3 b) {
    return vec3(a.x * b.x, a.y * b.y, a.z * b.z);
}

vec4 Mul(vec4 a, vec4 b) {
    return vec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}