I have an algorithm which generates from three to six points of intersection between a plane and the edges of a cube which contains that plane. For drawing the plane (which gets drawn a polygon) OpenGL needs the vertex to be ordered as in the following picture:
If the vertex are unordered, this result may be drawn:
Edit: I found this question but I don't know how to code it in Python and that's not exactly what I need
If points were built as intersections between a plane and the edges of a cube, then they form convex polygon.
To properly order vertices of this polygon, make projection onto some plane - or onto section plane, or onto one of OXY, OXZ, OYZ planes - just choose one not normal to section plane and make corresponding component zero.
Then choose the leftmost point in that plane as base and sort other points by polar angle relative to base.
Related
I have a set of 3d points in a txt file in the form of (x,y,z) as shown in figure 1. I want to specify the boundaries of these points as in figure 2 such that if any new points were added outside the boundaries they are deleted as the blue points, and if they are inside the boundaries as the green ones they are kept. How can I achieve that in python? I tried convex hull but it only gets the boundary points !
The real data can be found here, I used figures for simplification. https://drive.google.com/file/d/1ei9NaJHN922pYItK2CRIXyLfwqm_xgrt/view?usp=sharing
Figure 1
Figure 2
For 2D points, you can apply the test as described in Wikipedia:
One simple way of finding whether the point is inside or outside a simple polygon is to test how many times a ray, starting from the point and going in any fixed direction, intersects the edges of the polygon. If the point is on the outside of the polygon the ray will intersect its edge an even number of times. If the point is on the inside of the polygon then it will intersect the edge an odd number of times. The status of a point on the edge of the polygon depends on the details of the ray intersection algorithm.
The n-dimensional case involves a convex hull test and requires linear programming techniques as described here.
In a nutshell:
I need an algorithm that can generate points on the surface of a sphere, and the euclidean distance between each point and its neighbors must be the same.
Here is a quick explanation about what I mean about that:
If the sphere was represented as a "geodesic polyhedron" ("geodesic sphere"), each side of all the triangles would have the same length. Note that it doesn't have to be a Geodesic grid or a geodesic polyhedron, it could be something else. I'm open to all suggestions.
The difficulty is that we must be able to specify the distance between the neighbouring points.
If it was a graph I would say that the edges should be the same length, and that the distance between the adjacent nodes / vertices should the same.
What I'm looking for:
an existing libray / function or algorithm that already solves this problem (but I doubt that it would be the case because I did a lot of research)
an implementation
Constraints of the algorithm:
Output:
an array of 3D (x,y,z) coordinates.
Input parameters:
3D (x,y,z) coordinates of the sphere center
radius of the sphere
distance between neighbouring points (adjacent nodes)
What I've done:
I did a lot of research about the subject
I've read a lot of papers an articles
I implemented some algorithms I found
I found a lot of good papers and resources about related problems, but nothing for this specific case. So after days of research, I ask people that have specialised knowledge of this area some help.
The closest solution I've found is the Deserno algorithm (see link below), but the problem is that its input parameters are the radius and a number of points to generate (we can't sepcify the coordinates of the sphere center an the distance between neighbouring points).
If it helps, here are some related questions and useful resources:
Evenly distributing n points on a sphere
Plotting points on the surface of a sphere in Python's matplotlib
https://en.wikipedia.org/wiki/Geodesic_grid
https://en.wikipedia.org/wiki/Geodesic_polyhedron
https://en.wikipedia.org/wiki/Spherical_polyhedron
Deserno algorithm: https://www.cmu.edu/biolphys/deserno/pdf/sphere_equi.pdf
Some representations to give an idea:
Evenly distributed points:
Geodesic grid / geodesic polyhedron:
Geodesic polyhedron zoom:
Here, each point is at 10 centimeters of distance from its neighbors.
I want to calculate intersection points of polyline and a closed 3D surface (given as a set of polygons).
For simple 2D cases I can use shapely. Can you advice me something for 3D case?
P.S. My programming language is Python, but C++ libraries can be useful too.
Consider every line segment and every polygon independently and build their axis-aligned bounding boxes. Now for every pair of overlapping boxes, rotate the polygon to the horizontal plane, and the segment accordingly, and find the piercing point of the supporting line of the segment.
Then check if the piercing point belongs to the segment and to the inside of the polygon.
I'm trying to have the smooth direction from a point to a polygon mesh.
It's not the shortest path direction but one that is interpolated from the mesh normals.
The way I'm going about it is to "extrude" the points of polygons along their normals with linePlane intersection between each prim point and normal and a plande defined by P and the plane normal.
I guess the first issue is assess to which polygon the point will belong to. I using a clumbsy way but sort of works. What's bothering me the most is actually after "extruding" the points and making the polygon co-planar with the point, I need to find on the orginal polygon the same relative position it has in the extruded one.
I can raycast, so I was wondering if I could just infer somehow the direction back to the orginal poly and get the corresponding position with its hit.
Is is this a common problem with a name, any references I should check?
Rationale:
For my project i use 2D images from a telescope. The outer border of each image is known to be oversatured with points due to telescope malfunction. Therefor i want to extract the points that make up the outer border of the 2D image.
So what i want to do is somehow extract the points that make up the outer shell, with a desired width of the shell according to my preference.
What i have tried so far:
In Python i have tried finding the points that make up the edge by using scipy.ConvexHull to find the outer points and then removing these points. When doing this in a loop it should remove the outer edge with a width dependant on the amount of iterations. However, this method is dependant on the point density, and removes less points for places on the edge where the density is large. What i want is that an about equal width of outer edge is removed of the whole image, see images below :
To show what i mean, i have added the ConvexHull result, in red the points it gives as outer edge points after 15x iterations:
For clarification, this is the desired result i would like my algorithm to give me, an outer edge with equal width over the whole image, which is independant of point density.
Since you showed only ideas and graphics without code, I will do the same.
I see several ways to get the smaller polygon within your convex hull with a near-constant width between them. There are also variations on each. I illustrate with a convex hull that is a simplified version of the one in your graphics. Each of my solutions ignores the majority of points in the problem and uses only the vertices of the convex hull, so the "point density" is ignored.
Before choosing a polygon, you could find the "center point" of your convex hull. There are multiple ways to define this. You could use the centroid of the vertices of the hull, where the x- and y-coordinates are the averages of the coordinates of the vertices, but this biases toward parts of the hull with many small segments. You could use the center of the bounding rectangle, where the x- and y-coordinates are the average of the maximum and the minimum coordinates of the hull's vertices. This is the approach I used in my graphics. There are other possible "center points."
My first inner polygon moves each vertex a proportional distance toward the center point. In my example, I moved each point one-fourth of the distance toward the center point.
My second inner polygon moves the vertices a fixed distance toward the center point. I chose a distance one-fourth of the average distance of the vertices from the center point. Note that for this particular example there is very little difference between this polygon and my previous one. The differences would be more obvious for a hull where come points are much closer to the center point than some other points.
My third polygon abandons the center point. It moves each side of the hull a fixed distance toward the inside of the hull. The intersections of these new segments are used to define the new polygon. In other words, I did "inward polygon offsetting" or "polygon buffering." This is a non-trivial task in computational geometry, but some discussion on this task and similar tasks can be found at this SO question. This does look different from the other polygons, since the smaller sides of the hull tend to shrink or completely disappear from the result.
Choose whichever polygon suits your needs--the first two are easier to compute than the third, but the third comes closest to your ideal of "equal width of outer edge."