-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: spatial manipulation matrices #1797
Comments
I went out of my way to create a minimal quasi-working example of what the |
I'm OK with this in principle. It would be worth looking into how gioui does tranforms since they have worked on efficient implementations that could be generalised to the cases here. |
gioui.org's affine transformation matrix. Edit: although after looking at gioui's methods, I'm bound to change quite a few things. |
@kortschak Ran into a conundrum adding shear/skew. I have the following signature for Compose and AddShear func ComposeAffine(translate, scale Vec, q Rotation, sxy, sxz, syx, syz, szx, szy float64) Affine
func (a Affine) AddShear(origin Vec, sxy, sxz, syx, syz, szx, szy float64) Affine Feel like the verbosity with all these floats might be too much to comfortably use these functions. // Hard to decipher which number corresponds to which shear plane/component.
a := ComposeAffine(r3.Vec{}, r3.Vec{}, r3.Rotation{}, 1, .2, 0, 0, math.Pi, 6) This could be solved by adding a |
Adding func ComposeAffine(translate Vec, scaleShear Warp, q Rotation) Affine
identityAffine := ComposeAffine(Vec{}, Warp{}, Rotation{}) The cool thing about this is that now the zero values of all arguments would yield the identity transform! |
Another question: What does shear XY do?
|
I'm not sure how much this applies to the conversation, but as far as math libraries for 2D and 3D rendering (ie opengl), I would suggest looking at, copying, or just using the excellent mathgl library instead of reinventing it. |
All respect to |
Background
Most (if not all) 3D renderers use spatial transformation matrices. For example, here is the documentation of three.js' Matrix4 type which allows for rotations and translations. Similarly, the corresponding matrix for 2D rotation+translation is a 3x3 matrix (three.js link).
Today there is a 3x3 spatial matrix implementation, the
r3.Mat
type. This type was thought of for use as a rotation tensor, which describes a complete rotation in 3D space, without translation. This is useful for studying rigid-body dynamics of arbitrarily oriented frames in space, such as is the case with planes and drones. However, its functionality is a far cry from aMatrix4
type, which brings rotation and translation into the equation, something which is crucial for 3D rendering.These matrices have been implemented in
sdfx
by Jason Harris in Go: https://github.com/soypat/sdf/blob/main/matrix.go. The "important" methods this matrix should have for the correct functioning of thesdf
package are as follows for the Matrix4 type:func NewMatrix4(data []float64) Matrix4
func (a Matrix4) MulPosition(b r3.Vec) r3.Vec
Worth mentioning three.js calls this "applying". Maybe that is a more apt nameApplyPosition
func (a Matrix4) Inverse() Matrix4
func (a Matrix4) Det() float64
func (a Matrix4) MulBox(box r3.Box) r3.Box
rotates/translates a 2d bounding box and resizes for axis-alignment. Maybe rename toApplyBox
func (a Matrix4) Scale(k float64) Matrix4
multiplies all values by k and returns new matrixMatrix3
should have corresponding methods of the same name too forr2
types.Proposal
Add a similar-to Matrix3 and Matrix4 types somewhere in the
spatial
package. My guess of the package name where it belongs is at best as good as yours (r2
,mat2
,mat
?) .Will
Matrix3
user3.Mat
, or should these methods be implemented forr3.Mat
? It seems as though the latter would mix too many responsibilities in one type i.e. a matrix that can be used for 3D rotations or 2D spatial transformations.Another idea is to add these types as
r3.Transform
(Matrix4
). The possible downside to this is that ifr2.Transform
wants to use the underlyingr3.Mat
type then there could be a future import cycle waiting to happen (I figure it would be more natural forr3
to importr2
).r3.Mat
type be entertained to figure out a elegant way to solve this?r3.Mat
logic could be moved to an internal package that can be shared betweenr2
andr3
.The code shown above uses "direct" types- they should probably be pointers to the Matrix though (?).
I am in no hurry to implement these so this proposal can serve as a floor to discuss the idea.
Zero value
The zero value of a Transformation matrix should be the Identity matrix, ideally.
Potential impact of proposal
3D renderer libraries are happy with gonum!
The text was updated successfully, but these errors were encountered: