mirror of
https://github.com/hannobraun/Fornjot
synced 2025-07-20 00:46:10 +00:00
Use planes to define vertices
This commit is contained in:
parent
a6b1bbfdcb
commit
f675fd3db6
6
experiments/2024-12-09/src/math/bivector.rs
Normal file
6
experiments/2024-12-09/src/math/bivector.rs
Normal file
@ -0,0 +1,6 @@
|
||||
use super::Vector;
|
||||
|
||||
pub struct Bivector<const D: usize> {
|
||||
pub a: Vector<D>,
|
||||
pub b: Vector<D>,
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
mod bivector;
|
||||
mod plane;
|
||||
mod point;
|
||||
mod scalar;
|
||||
mod vector;
|
||||
|
||||
pub use self::{point::Point, scalar::Scalar, vector::Vector};
|
||||
pub use self::{
|
||||
bivector::Bivector, plane::Plane, point::Point, scalar::Scalar,
|
||||
vector::Vector,
|
||||
};
|
||||
|
13
experiments/2024-12-09/src/math/plane.rs
Normal file
13
experiments/2024-12-09/src/math/plane.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use super::{Bivector, Point};
|
||||
|
||||
pub struct Plane {
|
||||
pub origin: Point<3>,
|
||||
pub coords: Bivector<3>,
|
||||
}
|
||||
|
||||
impl Plane {
|
||||
pub fn point_from_local(&self, point: impl Into<Point<2>>) -> Point<3> {
|
||||
let [u, v] = point.into().coords.components;
|
||||
self.origin + self.coords.a * u + self.coords.b * v
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
geometry::{Shape, Triangle, Vertex},
|
||||
math::{Bivector, Plane, Point, Vector},
|
||||
storage::Store,
|
||||
};
|
||||
|
||||
@ -7,16 +8,31 @@ pub fn model(shape: &mut Shape) {
|
||||
let mut vertices = Store::<Vertex>::new();
|
||||
let mut triangles = Store::<Triangle>::new();
|
||||
|
||||
let bottom = Plane {
|
||||
origin: Point::from([0., 0., -0.5]),
|
||||
coords: Bivector {
|
||||
a: Vector::from([1., 0., 0.]),
|
||||
b: Vector::from([0., 1., 0.]),
|
||||
},
|
||||
};
|
||||
let top = Plane {
|
||||
origin: Point::from([0., 0., 0.5]),
|
||||
coords: Bivector {
|
||||
a: Vector::from([1., 0., 0.]),
|
||||
b: Vector::from([0., 1., 0.]),
|
||||
},
|
||||
};
|
||||
|
||||
let (a, b, c, d, e, f, g, h) = shape
|
||||
.extend_with(&mut vertices)
|
||||
.add([-0.5, -0.5, -0.5])
|
||||
.add([0.5, -0.5, -0.5])
|
||||
.add([-0.5, 0.5, -0.5])
|
||||
.add([0.5, 0.5, -0.5])
|
||||
.add([-0.5, -0.5, 0.5])
|
||||
.add([0.5, -0.5, 0.5])
|
||||
.add([-0.5, 0.5, 0.5])
|
||||
.add([0.5, 0.5, 0.5])
|
||||
.add(bottom.point_from_local([-0.5, -0.5]))
|
||||
.add(bottom.point_from_local([0.5, -0.5]))
|
||||
.add(bottom.point_from_local([-0.5, 0.5]))
|
||||
.add(bottom.point_from_local([0.5, 0.5]))
|
||||
.add(top.point_from_local([-0.5, -0.5]))
|
||||
.add(top.point_from_local([0.5, -0.5]))
|
||||
.add(top.point_from_local([-0.5, 0.5]))
|
||||
.add(top.point_from_local([0.5, 0.5]))
|
||||
.get_added();
|
||||
|
||||
shape
|
||||
|
Loading…
x
Reference in New Issue
Block a user