I need to import a shape file of a drinking water network into a hydraulic software.
For this software I need intersections when lines are intersecting.
So I tried to create all intersections, but this did not bring the results I need.
Another degree of difficulty adds the fact that in hydraulic systems we have also crossing pipes, that have no connection with each other. So they would need to be excluded from the intersection. My first thought was to insert a limit length of 1-5cm for interecting lines. So if lines are crossing the limit length would be exceeded and the lines would not be intersected by the algorithm.
Can someone help me here? At least with the first step - creation of intersections?
Screenshot from one missing intersection
Challenge:
We have two lines.
Blue line passes through points : (20,100), (25,44.44), (30,30), (35,20), (40,0), (45,0), (50,0), (55,0), (60,0)
Pink line passes through points : (20,00), (25,0), (30,0), (35,0), (40,20), (45,33.33), (50,64.44), (55,100), (60,100)
Without any manual intervention, I want to know the point where they intersect. For example, the point of intersection as shown in figure is (37.5,10)
Remember: The only input of the program is set of points of two lines. Output needed is intersection point of both the line.
Things that did not work out:
I tried to find library of Python that can generate intersection point of two lines(both passing through more than two points). Couldn't find it.
I tried to find a mathematical equation generator for lines passing through more than two points. Then I thought I'll be able to find the intersection of those two equations. Got very complex with lots of polynomial equations!
Most of the places I searched in internet were able to give me intersection of two straight lines that passed through two points only. However as seen in the above image, the both the line passes through about 9 points.
Correct solution:
Well, call it a bummer or any but the solution wasn't as complex as I thought.
Now if you carefully look at the image, you can interpret it in this way:
Instead of calling it a line that passes from lots of points and not just two points, call it a line that is passing through two points. Then it is passing through another two points. Then another two points.. so on..
There are many solutions available online for finding intersection of lines that passes through 2 points. The problem here was only because of the interpretation that both the lines are passing through N number of points (N>2).
Hence, the answer is calculated this way
Step 1: Check for intersection of line1 with first two points [(20,100),(25,44.44)] and line2 with first two points[(20,0.0),(25,0.0)]
Step 2: Check for intersection of line1 with next two points [(25,44.44),(30,30)] and line2 with first two points[(25,0.0),(30,0)]
Step 3: Repeat this process for the whole loop of points till the last point is reached.
Output: The program was able to yield (37.5,10) correctly!
PS: I can share the code of this if need be.
I have the two points p1 and p2 and the line l (black). The line is made of 100+ internal points arranged in an array starting from p1 and ending in p2.
Now, I would like to convert the curved line to a "straight" line like the red line on the above illustration. I am, however, a little unsure how to do this.
So far, my idea is to iterate the line with a fixed distance (e.g. take all points from start and 100 pixels forward), calculate the curve of the line, if it exceeds a threshold, make the straigt line change direction, then iterate the next part and so on. I'm not sure this would work as intended.
Another idea would to make a greedy algorith trying to minimize the distance between the black and red line. This could, however, result in small steps which I would like to avoid. The steps might be avoided by making turns costly.
Are there any algorithms about this particular problem, or how would you solve it?
Search for the phrase polygonal chain simplification and you'll see there is quite a literature on this topic.
Here is one reference that could lead you to others:
Buzer, Lilian. "Optimal simplification of polygonal chains for subpixel-accurate rendering." Computational Geometry 42.1 (2009): 45-59.
I am trying to solve a programming interview question that requires one to find the maximum number of points that lie on the same straight straight line in a 2D plane. I have looked up the solutions on the web. All of them discuss a O(N^2) solution using hashing such as the one at this link: Here
I understand the part where common gradient is used to check for co-linear points since that is a common mathematical technique. However, the solution points out that one must beware of vertical lines and overlapping points. I am not sure how these points can cause problems? Can't I just store the gradient of vertical lines as infinity (a large number)?
Hint:
Three distinct points are collinear if
x_1*(y_2-y_3)+x_2*(y_3-y_1)+x_3*(y_1-y_2) = 0
No need to check for slopes or anything else. You need need to eliminate duplicate points from the set before the search begins though.
So pick a pair of points, and find all other points that are collinear and store them in a list of lines. For the remainder points do the same and then compare which lines have the most points.
The first time around you have n-2 tests. The second time around you have n-4 tests because there is no point on revisiting the first two points. Next time n-6 etc, for a total of n/2 tests. At worst case this results in (n/2)*(n/2-1) operations which is O(n^2) complexity.
PS. Who ever decided the canonical answer is using slopes knows very little about planar geometry. People invented homogeneous coordinates for points and lines in a plane for the exact reason of having to represent vertical lines and other degenerate situations.
Mapping a point cloud onto a 3D "fabric" then flattening.
So I have a scientific dataset consisting of a point cloud in 3D, this point cloud comprises points on a surface that is curved. In order to perform quantitative analysis I however need to map these point clouds onto a surface I can then flatten. I thought about using mapping tools sort of like in the case of the 3d world being flattened onto a map, but not sure how to even begin as I have no experience in cartography and maybe I'm trying to solve an easy problem with the wrong tools.
Just to briefly describe the dataset: imagine entirely transparent curtains on the window with small dots on them, if I could use that dot pattern to fit the material the dots are on I could then "straighten" it and do meaningful analysis on the spread of the dots. I'm guessing the procedure would be to first manually fit the "sheet" onto the point cloud data by using contours or something along those lines then flattening the sheet thus putting the points into a 2d array. Ultimately I'll probably also reduce that into a 1D but I assume I need the intermediate 2D step as the length of the 2nd dimension is variable (i.e. one end of the sheet is shorter than the other but still corresponds to the same position in terms of contours) I'm using Matlab and Amira though I'm always happy to learn new tools!
Any advice or hints how to approach are much appreciated!
You can use a space filling curve to reduce the 3d complexity to a 1d complexity. I use a hilbert curve to index lat-lng pairs on a 2d map. You can do the same with a 3d space but it's easier to start with a simple curve for example a z morton order curve. Space filling curves are often used in mapping applications. A space filling curve also adds some proximity information and a new sort order to the 3d points.
You can try to build a surface that approximates your dataset, then unfold the surface with the points you want. Solid3dtech.com has the tool to unfold the surfaces with the curves or points.