Added linear algebra package.
This commit is contained in:
parent
386eb28f11
commit
ca6e592cec
22
lin/projection32.go
Normal file
22
lin/projection32.go
Normal file
@ -0,0 +1,22 @@
|
||||
package lin
|
||||
|
||||
import "opslag.de/schobers/geom"
|
||||
|
||||
func basisToPoints(p1, p2, p3, p4 geom.PointF32) geom.Matrix3x3F32 {
|
||||
var m = geom.Mx3x3F32(geom.Vec3F32(p1.X, p1.Y, 1), geom.Vec3F32(p2.X, p2.Y, 1), geom.Vec3F32(p3.X, p3.Y, 1))
|
||||
var v = m.Adj().MulV(geom.Vec3F32(p4.X, p4.Y, 1))
|
||||
return m.MulM(geom.Mx3x3F32(geom.Vec3F32(v.X, 0, 0), geom.Vec3F32(0, v.Y, 0), geom.Vec3F32(0, 0, v.Z)))
|
||||
}
|
||||
|
||||
// Projection32 calculates the projection matrix to transformation a point in rectangle src1, src2, src3, src4 to a point in rectangle dst1, dst2, dst3 and dst4.
|
||||
func Projection32(src1, dst1, src2, dst2, src3, dst3, src4, dst4 geom.PointF32) geom.Matrix3x3F32 {
|
||||
var s = basisToPoints(src1, src2, src3, src4)
|
||||
var d = basisToPoints(dst1, dst2, dst3, dst4)
|
||||
return d.MulM(s.Adj())
|
||||
}
|
||||
|
||||
// Project32 projects a point pt using the projection matrix p and returns the resulting point.
|
||||
func Project32(p geom.Matrix3x3F32, pt geom.PointF32) geom.PointF32 {
|
||||
var res = p.MulV(geom.Vec3F32(pt.X, pt.Y, 1))
|
||||
return geom.PtF32(res.X/res.Z, res.Y/res.Z)
|
||||
}
|
Loading…
Reference in New Issue
Block a user