Last active
June 29, 2016 00:26
-
-
Save hgiesel/a601676c070ddd720ef315520b8cedf7 to your computer and use it in GitHub Desktop.
Calculating if a point (x,y) is in between two other points on a plane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct point { | |
int x; | |
int y; | |
} | |
void is_between(struct point the_point, struct point a, struct point b) { | |
int cross_product = (the_point.y - b.y) * (a.x - b.x) - (the_point.x - b.x) * (a.y - b.y); | |
if (abs(cross_product) != 0) { | |
return false; | |
} | |
int dot_product = (the_point.x - b.x) * (a.x - b.x) + (the_point.y - b.y) * (a.y - b.y); | |
if (dot_prouduct < 0) { | |
return false; | |
} | |
int squaredlengthba = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); | |
if (dot_product > squaredlengthba) { | |
return false; | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:check_if_cursor_in_cursors(thecursor, a, b) | |
" row = 1 , column = 2 | |
if a:thecursor[1] ># a:a[1] && a:thecursor[1] <# a:b[1] | |
return 1 | |
elseif a:thecursor[1] ># a:a[1] && a:thecursor[1] ==# a:b[1] && | |
\ a:thecursor[2] <=# a:b[2] | |
return 1 | |
elseif a:thecursor[1] ==# a:a[1] && a:thecursor[2] >=# a:a[2] && | |
\ a:thecursor[1] <# a:b[1] | |
return 1 | |
elseif a:thecursor[1] ==# a:a[1] && a:thecursor[2] >=# a:a[2] && | |
\ a:thecursor[1] ==# a:b[1] && a:thecursor[2] <=# a:b[2] | |
return 1 | |
endif | |
return 0 | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment