123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'package:fis_measure/interfaces/date_types/point.dart';
- import 'package:fis_measure/interfaces/date_types/vector.dart';
- class LineUtils {
-
- static DPoint? calculateIntersection(
- DPoint startA,
- DPoint endA,
- DPoint startB,
- DPoint endB,
- ) {
- return _getIntersectionPointCloneCSharp(startA, endA, startB, endB);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- static bool isPointOnLine(DPoint p1, DPoint p2, DPoint point) {
-
- DVector v = p2 - p1;
- DVector w = point - p1;
-
- double crossProduct = v.x * w.y - v.y * w.x;
- double dotProduct = _dotVector(v, w);
-
-
- return crossProduct.abs() < 1e-10 &&
- dotProduct >= 0 &&
- dotProduct <= _dotVector(v, v);
- }
- static double _dotVector(DVector a, DVector b) {
- return a.x * b.x + a.y * b.y;
- }
- static DPoint? _getIntersectionPointCloneCSharp(
- DPoint p1, DPoint p2, DPoint p3, DPoint p4) {
- double denom =
- (p4.x - p3.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p4.y - p3.y);
- if (denom == 0) return null;
- double t1 =
- ((p3.x - p1.x) * (p3.y - p4.y) - (p3.y - p1.y) * (p3.x - p4.x)) / denom;
- return DPoint(p1.x + t1 * (p2.x - p1.x), p1.y + t1 * (p2.y - p1.y));
- }
- }
- class _IntersectionTempLine {
- final double slope;
- final double intercept;
- final bool isVertical;
- _IntersectionTempLine(this.slope, this.intercept, this.isVertical);
- factory _IntersectionTempLine.fromPoints(DPoint p1, DPoint p2) {
- if (p1.x == p2.x) {
-
- return _IntersectionTempLine(double.nan, p1.x, true);
- } else {
-
- double m = (p2.y - p1.y) / (p2.x - p1.x);
-
- double b = p1.y - m * p1.x;
- return _IntersectionTempLine(m, b, false);
- }
- }
- }
|