Showing
3 changed files
with
21 additions
and
25 deletions
fractional/notes/polyhedra.pdf
0 → 100644
No preview for this file type
... | ... | @@ -245,29 +245,25 @@ where T: Add<Output = T> + Sub<Output = T> + Neg<Output = T> |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | - // https://rechneronline.de/pi/tetrahedron.php | |
248 | + // construct via cube, see polyhedra.pdf | |
249 | 249 | pub fn tetrahedron(a :T) -> Polyeder<T> { |
250 | - let f0 :T = 0.into(); | |
251 | - let f3 :T = 3.into(); | |
252 | - let f4 :T = 4.into(); | |
253 | - let f6 :T = 6.into(); | |
254 | - let f12 :T = 12.into(); | |
255 | - | |
256 | - let yi :T = a / f12 * T::sqrt(f6).unwrap(); | |
257 | - let yc :T = a / f4 * T::sqrt(f6).unwrap(); | |
258 | - let zi :T = T::sqrt(f3).unwrap() / f6 * a; | |
259 | - let zc :T = T::sqrt(f3).unwrap() / f3 * a; | |
260 | - let ah :T = a / 2.into(); | |
261 | - | |
262 | - let ps = vec!( Point::new( f0, yc, f0) | |
263 | - , Point::new(-ah, -yi, -zi) | |
264 | - , Point::new( ah, -yi, -zi) | |
265 | - , Point::new( f0, -yi, zc) ); | |
266 | - | |
267 | - let fs = vec!( Face::new(vec!(1, 2, 3), &ps) | |
268 | - , Face::new(vec!(1, 0, 2), &ps) | |
269 | - , Face::new(vec!(3, 0, 1), &ps) | |
270 | - , Face::new(vec!(2, 0, 3), &ps) ); | |
250 | + let f2 :T = 2.into(); | |
251 | + let ch = a / (f2 * T::sqrt(f2).unwrap()); | |
252 | + | |
253 | + let ps = vec!( Point::new(-ch, -ch, ch) // A | |
254 | + , Point::new(-ch, ch, -ch) // C | |
255 | + , Point::new( ch, -ch, -ch) // E | |
256 | + , Point::new( ch, ch, ch) ); // G | |
257 | + | |
258 | + // bottom: 1, 2, 3 | |
259 | + let fs = vec!( Face::new(vec!(2, 1, 0), &ps) // bottom | |
260 | + , Face::new(vec!(3, 2, 0), &ps) | |
261 | + , Face::new(vec!(0, 1, 3), &ps) | |
262 | + , Face::new(vec!(1, 2, 3), &ps) ); | |
263 | + //let fs = vec!( Face::new(vec!(0, 1, 2), &ps) // bottom | |
264 | + // , Face::new(vec!(0, 2, 3), &ps) | |
265 | + // , Face::new(vec!(3, 1, 0), &ps) | |
266 | + // , Face::new(vec!(3, 2, 1), &ps) ); | |
271 | 267 | |
272 | 268 | Polyeder{ points: ps, faces: fs } |
273 | 269 | } | ... | ... |
... | ... | @@ -36,8 +36,7 @@ use fractional::trigonometry::Trig; |
36 | 36 | use fractional::vector::Vector; |
37 | 37 | use fractional::transform::{TMatrix, Transformable}; |
38 | 38 | use fractional::xcb::XcbEasel; |
39 | - | |
40 | -use fractional::geometry::{Camera,DirectLight,Polyeder,Primitives}; | |
39 | +use fractional::geometry::{Camera, DirectLight, Polyeder, Primitives}; | |
41 | 40 | |
42 | 41 | fn mean(v: &Vec<i64>) -> Result<Fractional, TryFromIntError> { |
43 | 42 | let r = v.iter().fold(0, |acc, x| acc + x); |
... | ... | @@ -403,10 +402,11 @@ fn main() { |
403 | 402 | let xcb = XcbEasel::new().unwrap(); |
404 | 403 | let (tx, rx) = mpsc::channel(); |
405 | 404 | |
405 | + | |
406 | 406 | _democanvas( &xcb, "Something...(f64)", tx.clone() |
407 | 407 | , Polyeder::triangle(60.0) |
408 | 408 | , Polyeder::tetrahedron(80.0) |
409 | - , Polyeder::cube(55.0) | |
409 | + , Polyeder::cube(45.0) | |
410 | 410 | , DirectLight::new(Vector(0.0, 0.0, 1.0)) ); |
411 | 411 | /* |
412 | 412 | _democanvas( &xcb, "Something...(Fractional)", tx.clone() | ... | ... |
Please
register
or
login
to post a comment