How to find points that intersect an envelope of a line, but not the line itself? (Envelope of a geometry) - arcobjects

I have 2 layers. A lines layer and a points layer.
For any given line, how can I find the points that intersect the envelope of the line, but not the line itself, or more specifically, not the to point or from point of the line.
I can obviously find all the points that intersect the line's envelope, and then do 1 by 1 tests on the found points to see if they intersect the to or from points of the line, but I was hoping there is an easier, faster way to do something of this nature.
Edit:
An envelope or extent of a geometry is the smallest rectangle (polygon with 4 points) in which the geometry (polygon, polyline, line, etc.) will fit.
The below diagram illustrates the envelope for a polygon, but a polyline will work similarly.
Envelope http://www.freeimagehosting.net/uploads/cf344d3fe2.jpg

To find all points in the points layer that do not intersect an endpoint of a line in the lines layer, I would do this:
Create a Dictionary<string,IPoint> of points in the points layer.
Create a Dictionary<string,IPoint> of endpoints in the lines layer.
Loop through each key in the first dictionary and check to see if the key exists in the second dictionary.
The string key is based on a concatenation of X, comma, and Y.

Related

Extract contour from obj 3d object in Matlab

I have an .obj file representing a 3D object.
I need to extract from this 3D object the contour that is obtained by intersection with a plane. So for example, I have an object representing a cylinder oriented with vertical axis, then I want to extract a circle contour when the intersecting plane is horizontal or a rectangular contour when the intersection plane is vertical. Any suggestion about how to do it?
Since I didn't know how to visualise this obj file, I have converted to a patch with the following code (some function taken from loadawobj from Matlab file exchange).
modelname='file.obj';
S=loadawobj(modelname);
mtl=loadawmtl(['obj/' S.mtllib]);
p3=patch('Vertices',S.v','Faces',S.f3');
for ii=1:length(S.umat3)
mtlnum=S.umat3(ii);
fvcd3(ii,:)=mtl(1).Kd';
end
p3.FaceVertexCData=fvcd3;
p3.FaceColor='flat';
But I don't necessarily need to extract the contour from the resulting patch if this is too complex to accomplish. If there is an easier procedure starting from the obj file, it's also fine and acceptable. Thank you!
That's the way I solved the problem, after collecting information all around the web. I couldn't find anything ready on line so I had to implement an algorithm on my own. The basic idea is very simple but there are many steps required. I start from two info: one array containing the coordinates of the cloud point and another array containing a bunch of tuples about how the 3 vertex are connected to form a triangle.
First of all you need to find a representation of the plane you want to use for your cutting. That means you just use one point and the normal to the plane to represent it. That plane is required in order to identify the cutting point on the structure.
Second step is to identify the triangles on the plane. In few words you just need to scroll over all the triangles of the structure and find those having one corner above the cutting plane and another corner below the cutting plane. Also don't forget to account for the condition where one corner is on the plane or two are on the plane. All the other triangles are not needed, since they are totally above or below the cutting plane.
Now you have a subset of all your triangles. You need to extract points of the contour. So for each triangle you have 3 vertex: in general case you can imagine that one vertex is above the plane and the other two are below. Then you have two lines cutting the plane. You can extract two point by simply intersecting these lines with the cutting plane.
By repeating this operation you get a series of points on 2D space. But they have no order and if you plot them as a continuous plot, you get lines jumping up and down since the points you have extracted are randomly located in the array. So, it's required to order them in a proper way. The method I used is the very simple: start from one point and connect to the closest one. There are some bad situations where that doesn't work but you can probably avoid it by adding some more rules on the algorithm.

Find co-ordinates where LineString intersects a Polygon border in turfjs

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.

Intersection points between a long list of segments

I'm writing a Matlab program that has to do the following thing I'm stuck with.
I have a file containing the names of two points on every line (the points have its respective coordinates in the space). Let's say the segments are airways and the points are airports.
I have plotted all the airways, and obviously some of them intersect at some point. I would like to draw a cross 'X' at those points of intersection. How can I do this? Is there any already-implemented Matlab function that allows me to find the intersection points of segments?
And another question related to this, provided the file (with about 100 lines, where in every line a segment is defined by two points) should I do a loop that checks all the intersecting points of the first segment with the other 99 segments, and then the second segment with the other 98 segments? Or there is a more efficient way in order to do that? Thank you!!!

Intersection of segment with polygon

I have to create a function in MATLAB that performs the following task:
Input:
p polygon in the form
p = [x1,y1; x2,y2; x3,y3; x4,y4...]
s struct with the segment from A to B
s = struct('A',[x,y],'B'[u,w])
Return:
1) An integer indicating how many intersections there are between the segment and the polygon (e.g., 0,1,2)
2) A new segment from A to B, where A is the first intersection or the initial point of the input segment and B the second point of the intersection or the last point of the segment input.
I have an idea on how to do it by using the function inpolygon. I have been reading how to use this function, and know that to use that, I should provide a query point and the coordinates of the polygon vertices. It will return 1 or 0 depending on whether it is inside or not.
My question is, how can I get the query point of the segment that is placed exactly in the boundary (in the case that the segment intersects with it)?
If you have the Mapping Toolbox installed, you could use polyxpoly. As this is a rather basic problem, there are quite a few free MATLAB-codes out there on the File Exchange. Here is what I found for the search term 'polygon intersect':
2D Polygon edges intersection by Bruno Luong
Find the intersection points of the edges of two 2D polygons, a simple function made to follow up a Newsgroup discussion
Curve Intersect 2 by Sebastian Hölz
This file is based on the Curve Intersect function by Duane Hanselman. It extends the scope of the function to handle arbitrary lines / polygons, which may also have vertical segments or segments with non-increasing x-values.
Curve intersections by NS
While a few other functions already exist in FEX that compute the
intersection points of curves, this short piece of code was written
with speed being the highest priority. No loops are used throughout,
taking full advantage of MATLAB's vectorization capabilities
Fast and Robust Curve Intersections by Douglas Schwarz
This function computes the (x,y) locations where two curves intersect. The curves can be broken with NaNs or have vertical segments. It is also very fast (at least on data that represents what I think is a typical application).
geom2d by David Legland
[...] derive new shapes: intersection between 2 lines, between a line and a circle, parallel and perpendicular lines

Use $within with a buffered MondoDB Linestring

I need to evaluate the proximity of a Point to a LineString using MongoDB.
Because the $near operator can only compare a Point to another Point, I need to generate a polygon out of the LineString, so I can use the $within operator. The distance between the LineString and the edges of the polygon should represent the radius I want to search in, such as represented in red below:
What might be a useful algorithm in order to accomplish this?
I think much easier would be to write your own function
To find (perpendicular) distance between point and line and then creating thickness of poly-line by polygon means.
Where:
P0,P1 are line endpoints
P is point
d is distance between them
Line is defined as: p(t)=P0+(P1-P0)*t where t=<0.0,1.0>
So the function should do this:
create perpendicular line
q(t)=P+DQ*u where u=(-inf,+inf)
DQ is perpendicular vector to (P1-P0)
In 2D you can obtain it easily like this (x,y) -> (y,-x). In higher dimensions use cross product with some non coplanar vectors.
compute line vs. line intersection
there are tons of stuff about this so google or solve the equation yourself here you can extract mine implementation.
now after successful intersection
just compute d as distance between P and intersection point. Do not forget that parameter t must be in range. If not (or if no intersection) then return min(|P-P0|,|P-P1|)
[hints]
t and u parameters can be obtained directly from intersection test so if the perpendicular vector to (P1-P0) is normalized to size = 1 then the abs(u) parameter of intersection point is the distance
[notes]
I am not familiar with mongodb so if you have no means to use own tests inside then this answer is of coarse obsolete.
Unfortunately, MongoDB provides very basic geospatial query, so you should create the buffer by your own. You can read how to do it here: Computing a polygon that surrounds a multi-point line
If you have longitude/latitude coordinates like WGS84 you must adjust this code; Read here how to calculate distance between point on a sphere https://en.wikipedia.org/wiki/Haversine_formula