From d84747593102488a035fcc493c7e532921909a19 Mon Sep 17 00:00:00 2001 From: lkcl Date: Tue, 8 Oct 2019 12:05:57 +0100 Subject: [PATCH] --- simple_v_extension/vector_ops/discussion.mdwn | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/simple_v_extension/vector_ops/discussion.mdwn b/simple_v_extension/vector_ops/discussion.mdwn index 05e346d15..d2e351959 100644 --- a/simple_v_extension/vector_ops/discussion.mdwn +++ b/simple_v_extension/vector_ops/discussion.mdwn @@ -125,6 +125,37 @@ From return { 'x':x_val_list, 'y':y_val_list, 'z':z_val_list, 'iteration':iterations_list } +Alternative in c: + + int i = 0; + int iterations = 0; // Number of times to run the algorithm + float arctanTable[iterations]; // in Radians + float K = 0.6073; // K + float v_x,v_y; // Vector v; x and y components + + for(i=0; i < iterations; i++) { + arctanTable[i] = atan(pow(2,-i)); + } + + float vnew_x; // To store the new value of x; + for(i = 0; i < iterations; i++) { + // If beta is negative, we need to do a counter-clockwise rotation: + if( beta < 0) { + vnew_x = v_x + (v_y*pow(2,-i)); + v_y -= (v_x*pow(2,-i)); + beta += arctanTable[i]; + } + // If beta is positive, we need to do a clockwise rotation: + else { + vnew_x = v_x - (v_y*pow(2,-i)); + v_y += (v_x*pow(2,-i)); + beta -= arctanTable[i]; + } + v_x = vnew_x; + } + v_x *= K; + v_y *= K; + # Vector Length -- 2.30.2