Created with <3 with dartpad.dev.
Created
November 22, 2022 03:49
-
-
Save leynier/46ec8445cc083432d117d747c01a9e05 to your computer and use it in GitHub Desktop.
jade-pomelo-4826
This file contains hidden or 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
void main() { | |
final p1 = Point(0, 0); | |
final p2 = Point(-5, -10); | |
final p3 = Point(-10, -5); | |
final p4 = Point(15, -5); | |
final r1 = Line(p1, p2); | |
final r2 = Line(p3, p4); | |
final pi = intersection(r1, r2); | |
print("${pi.x}, ${pi.y}"); | |
} | |
class Point { | |
const Point(this.x, this.y); | |
final double x; | |
final double y; | |
} | |
class Line { | |
const Line(this.one, this.two); | |
final Point one; | |
final Point two; | |
double get m => (two.y - one.y) / (two.x - one.x); | |
} | |
Point intersection(Line r1, Line r2) { | |
final x = (-1 * r1.m * r1.one.x + r2.m * r2.one.x + r1.one.y - r2.one.y) / (r2.m - r1.m); | |
final y = r1.m * (x - r1.one.x) + r1.one.y; | |
return Point(x, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment