Comments (2)
I found a working solution to the problem here.
https://stackoverflow.com/questions/68174332/how-to-define-self-intersection-of-polygon-in-google-maps-flutter
from maps_toolkit.
I tried it already but I didn't understand what max(x1,x2) and max(y1, y2) is doing and this gave me an error when implementing.
And also I tried below code it only works some cases.
import 'dart:core';
class LatLng {
double latitude;
double longitude;
LatLng(this.latitude, this.longitude);
}
bool doSegmentsIntersect(LatLng p0, LatLng p1, LatLng p2, LatLng p3) {
var denominator = (p3.longitude - p2.longitude) * (p1.latitude - p0.latitude) - (p3.latitude - p2.latitude) * (p1.longitude - p0.longitude);
var ua = (p3.latitude - p2.latitude) * (p0.longitude - p2.longitude) - (p3.longitude - p2.longitude) * (p0.latitude - p2.latitude);
var ub = (p1.latitude - p0.latitude) * (p0.longitude - p2.longitude) - (p1.longitude - p0.longitude) * (p0.latitude - p2.latitude);
if (denominator < 0) {
ua = -ua;
ub = -ub;
denominator = -denominator;
}
if (ua >= 0.0 && ua <= denominator && ub >= 0.0 && ub <= denominator && denominator != 0) {
return true; // Segments intersect
}
return false; // Segments do not intersect
}
void main() {
List<LatLng> coordArray = [
LatLng(0.0, 0.0),
LatLng(1.0, 1.0),
LatLng(0.5, 0.0),
LatLng(0.5, 1.0),
];
if (coordArray.length > 2) {
final n = coordArray.length - 1;
for (var i = 1; i < n; i++) {
for (var j = 0; j < i - 1; j++) {
final intersect = doSegmentsIntersect(coordArray[i], coordArray[i + 1], coordArray[j], coordArray[j + 1]);
if (intersect) {
print("Segments intersect");
return true; // Return true when an intersection is found
}
}
}
}
// If no intersection is found, return false
return false;
}
from maps_toolkit.
Related Issues (20)
- geodesic? HOT 1
- Getting the corners of a square gives mixed results
- to check if the retrieved points are inside polygon
- How to check distance from point to polygon (area)?
- The argument type 'LatLong' can't be assigned to the parameter type 'LatLng' HOT 1
- can't be assigned to the parameter type latlong2 package HOT 1
- PolygonUtil.containsLocation HOT 1
- Polygon Util to Compute Area Via The Path Irrespective of the Initial Point
- What Unit of Measurement is Being Used for The Area, Square Meters? HOT 3
- isLocationOnPath set TOLERANCE HOT 1
- Sort polygon points in counter-clock wise direction
- northeast and southwest
- [Feaature request] The LatLng constructor should be const
- how to update and calculate distance in polyline[help]
- PolygonUtil.decode is broken on web HOT 1
- Return driving distance on ComputeDistanceBetween HOT 1
- I'm not able to use google maps flutter LatLng in map_toolkit HOT 5
- Polygones intersection HOT 2
- Null safety support HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maps_toolkit.