Browse Source

fix construction of tetrahedron

master
Georg Hopp 6 years ago
parent
commit
6539d87e67
Signed by: ghopp GPG Key ID: 4C5D226768784538
  1. BIN
      fractional/notes/polyhedra.pdf
  2. 40
      fractional/src/geometry.rs
  3. 6
      fractional/src/main.rs

BIN
fractional/notes/polyhedra.pdf

40
fractional/src/geometry.rs

@ -245,29 +245,25 @@ where T: Add<Output = T> + Sub<Output = T> + Neg<Output = T>
}
}
// https://rechneronline.de/pi/tetrahedron.php
// construct via cube, see polyhedra.pdf
pub fn tetrahedron(a :T) -> Polyeder<T> {
let f0 :T = 0.into();
let f3 :T = 3.into();
let f4 :T = 4.into();
let f6 :T = 6.into();
let f12 :T = 12.into();
let yi :T = a / f12 * T::sqrt(f6).unwrap();
let yc :T = a / f4 * T::sqrt(f6).unwrap();
let zi :T = T::sqrt(f3).unwrap() / f6 * a;
let zc :T = T::sqrt(f3).unwrap() / f3 * a;
let ah :T = a / 2.into();
let ps = vec!( Point::new( f0, yc, f0)
, Point::new(-ah, -yi, -zi)
, Point::new( ah, -yi, -zi)
, Point::new( f0, -yi, zc) );
let fs = vec!( Face::new(vec!(1, 2, 3), &ps)
, Face::new(vec!(1, 0, 2), &ps)
, Face::new(vec!(3, 0, 1), &ps)
, Face::new(vec!(2, 0, 3), &ps) );
let f2 :T = 2.into();
let ch = a / (f2 * T::sqrt(f2).unwrap());
let ps = vec!( Point::new(-ch, -ch, ch) // A
, Point::new(-ch, ch, -ch) // C
, Point::new( ch, -ch, -ch) // E
, Point::new( ch, ch, ch) ); // G
// bottom: 1, 2, 3
let fs = vec!( Face::new(vec!(2, 1, 0), &ps) // bottom
, Face::new(vec!(3, 2, 0), &ps)
, Face::new(vec!(0, 1, 3), &ps)
, Face::new(vec!(1, 2, 3), &ps) );
//let fs = vec!( Face::new(vec!(0, 1, 2), &ps) // bottom
// , Face::new(vec!(0, 2, 3), &ps)
// , Face::new(vec!(3, 1, 0), &ps)
// , Face::new(vec!(3, 2, 1), &ps) );
Polyeder{ points: ps, faces: fs }
}

6
fractional/src/main.rs

@ -36,8 +36,7 @@ use fractional::trigonometry::Trig;
use fractional::vector::Vector;
use fractional::transform::{TMatrix, Transformable};
use fractional::xcb::XcbEasel;
use fractional::geometry::{Camera,DirectLight,Polyeder,Primitives};
use fractional::geometry::{Camera, DirectLight, Polyeder, Primitives};
fn mean(v: &Vec<i64>) -> Result<Fractional, TryFromIntError> {
let r = v.iter().fold(0, |acc, x| acc + x);
@ -403,10 +402,11 @@ fn main() {
let xcb = XcbEasel::new().unwrap();
let (tx, rx) = mpsc::channel();
_democanvas( &xcb, "Something...(f64)", tx.clone()
, Polyeder::triangle(60.0)
, Polyeder::tetrahedron(80.0)
, Polyeder::cube(55.0)
, Polyeder::cube(45.0)
, DirectLight::new(Vector(0.0, 0.0, 1.0)) );
/*
_democanvas( &xcb, "Something...(Fractional)", tx.clone()

Loading…
Cancel
Save