I am having trouble figuring this out, I have 2 points A & B, I need to draw a straight line, and then see if this line intersects with circle C
What is the best way to do this? (I am new to Postgres so details would be super appreciated), steps to do:
draw line from A to B
see if line L intersects circle C of radius R
You can use ST_MakeLine to create a line from two points and ST_Intersects to see if it intersects with the circle.
But it is probably easier to use the <-> distance operator to see if the distance of the line from the center is less than the radius.
Related
I'm using canny edge detection to detect the edges of a rope and eliminate the background, then using morphological filters I'm filling these edges then thinning them to be in pixel size. The plot indicates the xy coordinates of the rope. What I need to do is to get the intersection of the scattered data (blue *) with the red circle (get the coordinates of Points (1,2,3,4).
Then I need to get the whole points coordinates from the point of intersection (point1,2,3,4) to the center,grouped as A,B,C,D.
The center of the circle, the origin of the axes, and the radius are all known.
I've tried some Matlab functions to get the four intersections points like
InterX,intersections
and also I tried to manually find the intersections
idx=find(y1-y2<eps);
but no method gives me the 4 intersection points.
Thank you in Advance
You'll need a thick circle. I presume (from your previous question) that the rope points are at contiguous integer coordinates. Using a thick circle (donut) with a width of 1 ensures you'll find at least one point in each rope end. Connected component analysis will then tell you which of these points belong to the same rope end.
Is there a way in Turfjs to determine the co-ordinates at which a LineString intersects with the border of a polygon?
There's a number of ways to find out if a point is within a polygon and a number of ways to find out if a point is on a line and so on, but I can't seem to figure out a way to ask "at what point does this line intersect this polygon's border".
I could enumerate the points in the polygon using a line intersection algorithm to find that point but I was wondering if there's a more "turf" way of doing this.
For context, I've loaded a GPX track and want to estimate the location/time at which the track enters/exits a defined area.
Because a GPX track only records locations at specific intervals it usually the case that pN recorded at time tN is outside the area and pN+1 recorded at time tN+1 is inside the area.
If I can get the point at which line (pN, pN+1) intersects the polygon's border I can estimate the exact time the track crosses into the polygon.
Ultimately, turfjs does not seem to have an API for doing this.
I was able to get the answer I wanted by enumerating the points in the polygon from the GeoJSON object to construct a sequence of line segments and then I used maxogden/geojson-js-utils linesIntersect function to test for intersection points.
I don't see a Turf function that does exactly that, but there is intersect, which finds the area of intersection between two polygons.
You could:
Construct a polygon by joining the line to itself reversed (so ABC becomes ABCBA)
Find the intersection of ABCBA and P, the original polygon using Intersect.
The intersection should be a zero-area polygon that is the part of ABCBA inside P. Somehow compute the length of it (strangely there's no perimeter function).
Subtract that length from the original length of ABC.
Not exactly elegant, true. :)
EDIT
Tried this. Turns out Turf-intersect doesn't return intersections if one of the polygons is zero-area.
This question already exists:
Closed 10 years ago.
Possible Duplicate:
intersection of line and circle with different slope
I have line which plotted by pp=randi([-400 400],2,2) then x=pp(:,1) and y=pp(:,2). I have a circle with centre (a,b) with radius r
I want to check the intersection point of circle and the line.
I have used polyfit command to check the slope and intercept. Then I used lincirc command but the problem is if the line crosses only one point then the other point is also shown.
For example, if the line crosses one side and stops in the middle, it shows the other point as well which will not cross the boundary
You have a circle radius r centred at (a,b). You have a line. If you have plotted these points, you must have your data stored in x and y vectors, so you take the first and last of elements each as (x,y) coordinates. The first pair form the line start point and last pair the end point. Refer to these points as (c1,d1) and (c2,d2). Assuming that your lincirc function tells you there are 2 intersection points between line and circle, calculate
A1 = (c1-a,d1-b)
A2 = (c2-a,d2-b)
Now if
norm(A1,2) < r
then endpoint (c1,d1) is inside your circle, if
norm(A2,2) < r
then endpoint (c2,d2) is inside your circle.
If one of the points is inside the circle, then you only have one intersection point.
If neither point is inside the circle, then you know that your line crosses the circle twice (assuming that your lincirc function tells you there are 2 points)
If both points are inside the circle, then your lincirc function is lying to you.
This question already exists:
Closed 10 years ago.
Possible Duplicate:
intersection of line and circle with different slope
I have line which plotted by pp=randi([-400 400],2,2) then x=pp(:,1) and y=pp(:,2). I have a circle with centre (a,b) with radius r
I want to check the intersection point of circle and the line.
I have used polyfit command to check the slope and intercept. Then I used lincirc command but the problem is if the line crosses only one point then the other point is also shown.
For example, if the line crosses one side and stops in the middle, it shows the other point as well which will not cross the boundary
You have a circle radius r centred at (a,b). You have a line. If you have plotted these points, you must have your data stored in x and y vectors, so you take the first and last of elements each as (x,y) coordinates. The first pair form the line start point and last pair the end point. Refer to these points as (c1,d1) and (c2,d2). Assuming that your lincirc function tells you there are 2 intersection points between line and circle, calculate
A1 = (c1-a,d1-b)
A2 = (c2-a,d2-b)
Now if
norm(A1,2) < r
then endpoint (c1,d1) is inside your circle, if
norm(A2,2) < r
then endpoint (c2,d2) is inside your circle.
If one of the points is inside the circle, then you only have one intersection point.
If neither point is inside the circle, then you know that your line crosses the circle twice (assuming that your lincirc function tells you there are 2 points)
If both points are inside the circle, then your lincirc function is lying to you.
sorry if this question might seem simple but I couldn't figure it out.
Imagine two arbitrary Rectangles that are randomly overlaped so that their outlines intersect at only two locations. Now you cut the area of overlap out of Rectangle 1.
This "bitten Rectangle 1" has now the following points (vertices): (1) All points of Rectangle 1 that lie outside of Rectangle 2, (2) All points of Rectangle 2 that lie inside Rectangle 1 and (3) the two intersection points.
The problem know is the following: How can I get the order of the new points so that the functions plot(...) or fill(...) would draw the right "Bitten Rectangle 1"?
What I did so far:
I determined the convex hull of all the points that lie outside of Rectangle 2 + the intersection points. Then one has to add the new points that lie inside rectangle 1 (due to overlap with Rectangle 2) between the indices of the first and second intersection point also in the right order.
The problem with this convex hull approach is that it only works if the intersection points lie on different lines of Rectangle 1, because then they are part of the convex hull.
If they lie on the same line they are no longer treated as part of the convex hull.
What I'd need is a method to get the order of all possible points that lie on the convex hull and not only the outer most ones.
Hope anybody can help me...
Thank you in advance,
Patrick
In Matlab, there is an amazing function called polybool that let you do any set operation on polygons: http://www.mathworks.com/help/toolbox/map/ref/polybool.html
All you have to do is to define four arrays describing the rectangles (rect1x, rect1y, rect2x and rect2y) and to call [resultx resulty] = polybool('subtraction', rect1x, rect1y, rect2x, rect2y). The resulting arrays will be describing the "Bitten Rectangle 1".