how can i find the shortest point for each points in points cloud - shortest

I have two points dataset, which come from two mesh with an intersection. How can I find the shortest point in the 2nd dateset for each points in the first one?

Related

Find distance between two points

Essentially, I have a list of points that I know are all connected upwards, downwards, leftwards, rightwards, or diagonally. Given two points, I want to find the minimum number of points you would have to travel to get to the other point.
Update: ended up going with an A* (A star) algorithm
Link to matlab code of A star algorithm that I used: https://www.mathworks.com/matlabcentral/fileexchange/56877-a-astar-a-star-search-algorithm-easy-to-use

How to check if given 3d point is outside convex hull

I'm working on a science project. I have a list of xyz-coordinates of voronoi diagram vertices, and a list of points that create my protein's convex-hull (from triangulation). Now some of the vertices lie quite far from the hull and I'd like to filter them out. How can I do it in c++ ? For now it doesn't have to be super optimised, I'm only focused on removing those points.
visualization
I was also thinking to check if a line from voronoi vertex(red crosses) to center of protein(pink sphere) is intersecting with hull face at any point, but I'm not sure how to achive that.
I've read that you can check if a point is inside a polygon by counting the times an infinite line from the point is crossing the hull, but that was for two dimensions. Can similar approach be implemented to suit my needs ?
https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
Let's start with the two-dimensional case. You can find the solution to that on CS.SX:
Determine whether a point lies in a convex hull of points in O(logn)
The idea is that each two consecutive points on the convex hull define a triangular slice of the plane (to some internal point of the hull); you can find the slice in which your point is located, and check whether it's closer to the internal point than the line segment bounding the slide.
For the three-dimensional case, I'm guessing you should be able to do something similar, but the search for the 3 points forming the relevant triangle might be a little tricky. In particular, it would also depend on how the convex hull is represented - as in the 2-d case the convex hull is just a sequence of consecutive points on a cycle.
I know this doesn't quite solve your problem but it's the best I've got given what you've written...

Calculating shortest paths from points that originates mid-edge

I have a set of origin-destination coordinates that I want to calculate the shortest paths between them.
My origin-destination coordinates are sometimes located in the middle of a long straight-line road. However, the shortest path calculated by OSMnx/networkx will not consider that mid-edge to nearest-node path.
Is there any ready function in OSMnx or networkx that I can use to find shortest path that originates/ends in the middle of the road?
If there is no such function, I am thinking of using the following steps.
Get nearest edges of origin and destination
Get nodes of those nearest edges: let's say (a,b) for origin, and (c,d) for destination
Calculate distance of 4 possible combinations: a->c, a->d, b->c, b->d
Project origin/destination onto their nearest edges: let's call them o1 and e1
Calculate distance o1->a, o1->b, e1->c, e1->d
Add (5) distance to (3): to get
o1->a->c->e1
o1->a->d->e1
o1->b->c->e1
o1->b->d->e1
Select path with smallest distance
OSMnx produces a networkx graph object for routing/analysis. As you note, networkx shortest path calculation takes an origin and a destination node, so trying to calculate a shortest graph path from an edge midpoint won't work.
A couple things you could try:
try to set simplify=False when you create the graph to retain as many nodes in the middle of streets as possible.
if that doesn't work, you could try to subdivide edges (with greater than some threshold length) into 50 meter chunks or somesuch to discretize them with more nodes.
See also: https://stackoverflow.com/a/55601732/7321942

How to find closest points between two convex hull in MATLAB?

In part of an Artificial Neural Network matlab code, I want to find nearest points of two convex polygons.
I saw
dsearchn(X,T,XI)
command's description here, but that finds closest points between two sets of points, and polygons (like convexs) have infinites points.
So can you suggest any way/idea?
Notice: I'm using MATLAB 2014a. I have the coordinate of each convex's vertex point.
If you are not happy with what is provided by dsearchn, then, If I were you, I would do one of two following:
Find Nearest Neighbours on the vertices (for example which vertex of
polygon A is the NN of a given vertex of polygon B).
Pick a random point inside polygon A (you may want to compute the
convex hull of A, but you may skip that and take into account only
the vertices you know already). That random point is the query. Find
an NN of that point from the vertices of polygon B.
You may want to ask in Software recommendations for more.
Edit:
Another approach is this:
Create a representative dataset of polygon A. Set the size of the dataset yourself and fill it with samples of points that lie inside the polygon. Choose them uniformly randomly inside the polygon.
Then take a point of polygon B (either a vertex or a random point inside polygon B) and that's the query point, for which you will seek Nearest Neighbour(s) inside the representative dataset of polygon A.
Of course that's just an approximation, but I can't think of something else now.
Notice that you can of course do the same for polygon B.
With This File in File Exchange, I've find the solution.
With a little code modification, I have drawn a perpendicular bisector which I wanted. Of course, this way is time consuming.

How do I calculate the distance to the nearest point along a path?

I am looking for how to calculate the distance along a path in a binary array.
I imported a map as a matrix in matlab. There is a binary image of a river crossing two cities. I only found out how to calculate the distance from the river points to the nearest city but I don't manage to compute the shortest distance along the river.
I made a vector with the indices of all river points but I don't know how to get the distance to the nearest city from that...
Image
So I am looking for the shortest distance through the red line towards one of the light blue points it crosses !
Thnx
If I understand you in the right way it is not very difficult: Just do a dfs or bfs (8-neighbourhood) starting at each river-town and add sqrt(2) if you go diagonal and 1 if you go to a 4-neighbour. At each river pixel you can finally decide by taking the minimum value. You can develop it further stopping at river pixels with already smaller distance to another city...
I really hope I got you in the right way :)