Comments. Extra test circles.
This commit is contained in:
28
src/lib.rs
28
src/lib.rs
@@ -66,11 +66,11 @@ struct Ship {
|
||||
fn point_to_cga(x: f64, y: f64) -> CGA {
|
||||
let x_vec = CGA::e1();
|
||||
let y_vec = CGA::e2();
|
||||
let _z_vec =CGA::e3();
|
||||
let _z_vec =CGA::e3(); //This game assumes everything takes place in the plane.
|
||||
let e_vec = CGA::e4();
|
||||
let e_bar = CGA::e5();
|
||||
let n_vec = &e_vec + &e_bar;
|
||||
let n_bar = &e_vec - &e_bar;
|
||||
let n_vec = &e_vec + &e_bar; //Null vector for the point at infinity.
|
||||
let n_bar = &e_vec - &e_bar; //Null vector for the origin.
|
||||
|
||||
let mut ux = x;
|
||||
let mut uy = y;
|
||||
@@ -81,7 +81,7 @@ fn point_to_cga(x: f64, y: f64) -> CGA {
|
||||
mag_sqr = 1.;
|
||||
}
|
||||
|
||||
0.5*mag_sqr*n_vec + ux*x_vec + uy*y_vec - 0.5*n_bar
|
||||
0.5*mag_sqr*n_vec + ux*x_vec + uy*y_vec - 0.5*n_bar //F(x) = 1/2(x^2 n + 2x - nbar) = -1/2(x-e)n(x-e)
|
||||
}
|
||||
|
||||
fn point_to_screen_space(x: f64, y: f64) -> (f64, f64) {
|
||||
@@ -145,11 +145,8 @@ fn draw_line(context: &CanvasRenderingContext2d, line: &CGA) {
|
||||
|
||||
//draw_point(context, &point_to_cga(c_x, c_y));
|
||||
|
||||
//Convert into Canvas Space
|
||||
let (canvas_x, canvas_y) = point_to_screen_space(c_x, c_y);
|
||||
let canvas_r = r*RADIUS;
|
||||
|
||||
//Draw
|
||||
context.arc(canvas_x, canvas_y, canvas_r, 0., TWO_PI).unwrap();
|
||||
}
|
||||
context.stroke();
|
||||
@@ -185,6 +182,7 @@ pub fn start() -> Result<(), JsValue> {
|
||||
context.arc(CENTER_X, CENTER_Y, RADIUS, 0., TWO_PI).unwrap();
|
||||
context.stroke();
|
||||
|
||||
//Testing example lines and circles.
|
||||
let point = point_to_cga(0.,0.);
|
||||
draw_point(&context, &point);
|
||||
|
||||
@@ -194,7 +192,7 @@ pub fn start() -> Result<(), JsValue> {
|
||||
draw_point(&context, &p2);
|
||||
let p3 = point_to_cga(0.7, 0.6);
|
||||
draw_point(&context, &p3);
|
||||
let circle = &p1 ^ &p2 ^ &p3 ^ &CGA::e3();
|
||||
let circle = &p1 ^ &p2 ^ &p3 ^ &CGA::e3(); //wedge e3 to force into the plane
|
||||
draw_line(&context, &circle);
|
||||
|
||||
let p1 = point_to_cga(0.9, 0.2);
|
||||
@@ -215,5 +213,19 @@ pub fn start() -> Result<(), JsValue> {
|
||||
let circle = &p1 ^ &p2 ^ &p3 ^ &CGA::e3();
|
||||
draw_line(&context, &circle);
|
||||
|
||||
let p1 = point_to_cga(0.9, 0.);
|
||||
draw_point(&context, &p1);
|
||||
let p2 = point_to_cga(0.9, -0.1);
|
||||
draw_point(&context, &p2);
|
||||
let circle = &p1 ^ &p2 ^ &CGA::e4() ^ &CGA::e3(); //Wedge e4 to create a circle through p1 and p1 that is tangent to the unit circle.
|
||||
draw_line(&context, &circle);
|
||||
|
||||
let p1 = point_to_cga(0.9, 0.);
|
||||
draw_point(&context, &p1);
|
||||
let p2 = point_to_cga(0.9, -0.1);
|
||||
draw_point(&context, &p2);
|
||||
let circle = &p1 ^ &p2 ^ &CGA::e5() ^ &CGA::e3(); //Orthogonal to the line at infinity
|
||||
draw_line(&context, &circle);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user