From 6d356f0c681cb2bb0f26d848ed467f65c49769a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 9 Jan 2021 19:57:43 -0300 Subject: Implement polynomial gcd This was done to find the common roots between two polynomials. --- src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 13f13da..8831976 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,7 @@ fn main() { let b = Lerp::new(vec![400.0, 140.0, 500.0, 300.0]); let pa = poly::lp(a); let pb = poly::lp(b); + let p = poly::gcd(&pa, &pb); let sdl_context = sdl2::init().unwrap(); let video_subsystem = sdl_context.video().unwrap(); @@ -51,10 +52,13 @@ fn main() { for t in 0..800 { let x = eval_poly(&pa, t as Number / 800.0); let y = eval_poly(&pb, t as Number / 800.0); + let z = eval_poly(&p, t as Number / 800.0); canvas.set_draw_color(Color::RGB(180, 20, 20)); canvas.fill_rect(Rect::new(t, x as i32, 5, 5)).unwrap(); canvas.set_draw_color(Color::RGB(20, 180, 20)); canvas.fill_rect(Rect::new(t, y as i32, 5, 5)).unwrap(); + canvas.set_draw_color(Color::RGB(20, 20, 180)); + canvas.fill_rect(Rect::new(t, z as i32, 5, 5)).unwrap(); } canvas.present(); -- cgit v1.2.3