templates/basic-geometry-checks.cpp
compilable
$cat templates/basic-geometry-checks
Basic Geometry Checks
Triangle validity, Euclidean distance, and collinearity check using cross product.
#geometry#triangle#distance#collinear#cross-product
Log in to track progress, save custom versions, and organize into collections.Log In
$cat source_code/
cpp
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool isTriangle(ll a, ll b, ll c) {
if (a <= 0 || b <= 0 || c <= 0) return false;
return a + b > c && a + c > b && b + c > a;
}
double dist(double x1, double y1, double x2, double y2) {
double dx = x1 - x2, dy = y1 - y2;
return sqrt(dx * dx + dy * dy);
}
bool isCollinear(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3) {
return (y2 - y1) * (x3 - x1) == (y3 - y1) * (x2 - x1);
}17 linesutf-8
$cat explanation_notes.md
notes_viewer --renderedmarkdown (math enabled)
Basic Geometry Checks
Functions
Notes
isCollinear avoids slope computation, handles vertical lines correctlyll. Use __int128 for larger coords