played iwht matrix

This commit is contained in:
Jon Janzen
2021-04-02 19:02:57 -06:00
parent a4ffb3b7d6
commit 267bc15e2e
3 changed files with 44 additions and 0 deletions

11
Cargo.lock generated
View File

@@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "approx"
version = "0.4.0"
@@ -29,6 +31,14 @@ dependencies = [
"approx",
]
[[package]]
name = "matrix"
version = "0.1.0"
dependencies = [
"approx",
"structs",
]
[[package]]
name = "num-traits"
version = "0.2.14"
@@ -51,5 +61,6 @@ version = "0.1.0"
dependencies = [
"canvas",
"color",
"matrix",
"structs",
]

View File

@@ -10,3 +10,4 @@ edition = "2018"
canvas = { path = "canvas" }
color = { path = "color" }
structs = { path = "structs" }
matrix = { path = "matrix" }

View File

@@ -1,6 +1,7 @@
use canvas::Canvas;
use color::Color;
use structs::Tuple;
use matrix::Matrix;
use std::fmt;
use std::fs::File;
@@ -106,4 +107,35 @@ fn main() {
Err(e) => panic!("did not write. {}", e),
};
let i = Matrix::identity(4);
println!("{:#?}", i);
let inverse_i = i.inverse();
println!("{:#?}", inverse_i);
let mut a = Matrix::from_array([
[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 1.0]
]);
let mut b = a.inverse();
println!("{:?}", b);
let c = &a * &b;
println!("{:?}", c);
b.transpose();
a.transpose();
let at = a.inverse();
println!("{:?}", b);
println!("{:?}", at);
let t = Tuple::point(1.0, 2.0, 3.0);
let mut id = Matrix::identity(4);
id[1][3] = -3.0;
let q = &id * &t;
println!("{:?}", id);
println!("{:?}", q);
}