go-gl / mathgl

A pure Go 3D math library.
BSD 3-Clause "New" or "Revised" License
554 stars 65 forks source link

Add Scale() method #94

Open Zyl9393 opened 1 year ago

Zyl9393 commented 1 year ago

I have use for a method which takes a vector and returns a new vector where every element is the product of the respective elements of the vector and the elements of the receiver vector, e.g.:

func (v1 Vec3) Scale(v2 Vec3) Vec3{
    return Vec3{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]}
}

In my case I use it to scale the vertices of a 3D object with a per-axis-controllable factor, which is a common CGI feature to have to provide more artistic control over having just a single factor that gets used for each dimension.

It is trivially implementable and testable. This issue is mostly to discuss method name and whether this is wanted. I'm open to creating an MR if this is ok.

luisgargitter commented 8 months ago

Does a Matrix not do the trick?

v := Diag3(scale).Mul3x1(v)