Skip to content

Instantly share code, notes, and snippets.

@tvolkert
Created September 19, 2023 07:01
Show Gist options
  • Save tvolkert/2de82eaeaaa100c5528c767cbdd5ddb5 to your computer and use it in GitHub Desktop.
Save tvolkert/2de82eaeaaa100c5528c767cbdd5ddb5 to your computer and use it in GitHub Desktop.
import 'package:vector_math/vector_math_64.dart';
void main() {
Matrix4 transform = Matrix4(
1.0, 0.0, 0.0, 0.0, // nodartfmt
0.0, 1.0, 0.0, 0.0, // nodartfmt
0.0, 0.0, 1.0, 500, // nodartfmt
0.0, 0.0, 0.001, 1.5, // nodartfmt
);
// I want to find the source point that will yield destination point 1305,676
// when the transform is applied.
Vector3 points = transform.perspectiveTransform(Vector3(1305, 676, 0));
print('${points.x.truncate()},${points.y.truncate()}'); // 870,450
// So now we know that 1305,676 will transform to 870,450
// ... but what opint will transform to 1305,676?
// An inverse transform would seem to make sense...
Matrix4 inverse = Matrix4.inverted(transform);
Vector3 inversePoints = inverse.perspectiveTransform(Vector3(1305, 676, 0));
print('${inversePoints.x.truncate()},${inversePoints.y.truncate()}');
// wat?? that prints 1305,676, which is the source point!
// But we know that the source point transforms to 870,450
// So... what gives?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment