Find intersection between a 3D mesh and a line given by a sequence of point, using python - python

i have a 3D mesh (.vtk file) and a curve expressed as a sequence of points. I want to find the intersection point/points between the curve and the mesh. Does anyone know ho to something like that using python??
Thank you very much!!

Related

How to check if a 2D point is inside or outside a 2D Closed Bezier Curve using Python?

Hello,
in my 2d software i have two inputs available:
an array of XY points
[(x,y),(1,1),(2,2),(2,3),(-1,3),...]
and another matrix representing the closed 2D bezier curve handles
[((x,y),(x,y),(x,y)),
((-1,-1),(1,1),(1,2)),
((1,1),(2,2),(2,3)),
...]
How can i check if a point is inside or outside the given curve using python ? using preferably numpy maybe
I don't know how the theory of Bezier curves, so if your second list of points is a kind of compressed way to represent a Bezier curve, first try to sample some points of the curve with the precision you want.
So you have n points of your curve, and then you can apply a simple PIP algorithm : https://en.wikipedia.org/wiki/Point_in_polygon
I can explain in details later if you want to know how to do it programmatically.
I cant write code right here, because I need the entire program to understand properly, however I may provide two approaches how to do that.
The hardest way is to approximate each Bézier curve by a polyline. And then, according to the wiki you can use two techniques:
Ray casting algorithm: the shorthand of the algorithm: You put a ray, which starting from a point and goes through the entire polygon to an another point. Some lines lies inside a polygon, some outside. And then you check to which line belongs a specific point Looks like this:
Winding number algorithm: A little bit about winding numbers. So if a winding number is non-zero, the point lies inside the polygon
The huge drawback of this approach is that the accuracy depends on how close you approximated a curve to a polyline.
The second way is to use a bitmap. For example, you set your points to the white then render the area under the curve to the black and see if your points remain white. This method is more accurate and the fastest one, because you can use the GPU for the render.
And some links related to the first a approach:
https://pomax.github.io/bezierinfo/#intersections
http://web.mit.edu/hyperbook/Patrikalakis-Maekawa-Cho/node80.html

Python - Method to convert random points to line?

When I have some points its position is random as drawn below.
I want to dynamically draw lines with some restrictions.
1) No points in selected region.
2) The triangles are at acute angle.
3) Points are in X/Y (2D) plane.
So points are processed & divided therefore...
Can I find advice about any appropriate math solutions or even libraries?
You will want to look up Delaunay triangulation & Voronoi diagram; you can find implementation of these objects in scipy.interpolate; I think these constructs are what you are looking for.

Draw a curve joining a set of points in opencv python

I have a set of points extracted from an image. I need to join these points to from a smooth curve. After drawing the curve on the image, I need to find the tangent to the curve and represent it on the image. I looked at cv2.approxPolyDP but it already requires a curve??
You can build polyline, if order of points is defined. Then it is possible to simplify this polyline with Douglas-Peucker algorithm (if number of points is too large). Then you can construct some kind of spline interpolation to create smooth curve.
If your question is related to the points being extracted in random order, the tool you need is probably the so called 2D alpha-shape. It is a generalization of the convex hull and will let you trace the "outline" of your set of points, and from there perform interpolation.

Fitting a 3d points of an arc to a circle (regression in Python)

I am relatively new to python. My problem is as follows
I have a set of noisy data points (x,y,z) on an arbitrary plane that forms a 2d arc.
I would like a best fit circle through these points and return: center (x,y,z), radius, and residue.
How do I go about this problem using scipy in python. I could solve this using an Iterative method and writing the entire code for it. However, is there a way to best fit a circle using leastsq in python? and then finding Center and Radius?
Thanks
Owais
The scipy-cookbook has a long section on fitting circles:
http://www.scipy.org/Cookbook/Least_Squares_Circle

How do you calculate the area of a series of random points?

So I'm working on a piece of code to take positional data for a RC Plane Crop Duster and compute the total surface area transversed (without double counting any area). I cannot figure out how to calculate the area for a given period of operation.
Given the following Table Calculate the area the points cover.
x,y
1,2
1,5
4,3
6,6
3,4
3,1
Any Ideas? I've browsed Greens Theorem and I'm left without a practical concept in which to code.
Thanks for any advise
Build the convex hull from the given points
Algorithms are described here
See a very nice python demo + src
Calculate its area
Python code is here
Someone mathier than me may have to verify the information here. But it looks legit: http://www.wikihow.com/Calculate-the-Area-of-a-Polygon and fairly easy to apply in code.
I'm not entirely sure that you're looking for "Surface area" as much as you're looking for Distance. It seems like you want to calculate the distance between one point and the next for that list. If that's the case, simply use the Distance Formula.
If the plane drops a constant width of dust while flying between those points, then the area is simply the distance between those points times the width of the spray.
If your points are guaranteed to be on an integer grid - as they are in your example - (and you really are looking for enclosed area) would Pick's Theorem help?
You will have to divide the complex polygon approximately into standard polygons (triangles, rectangles etc) and then find area of all of them. This is just like regular integration (only difference is that you are yet to find a formula to approximate your data).
The above points are when you assume that you are forming a closed polygon with your data.
Use to QHull to triangulate the region, then sum the areas of the resulting triangles.
Python now conveniently has a library that implements the method Lior provided. https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html will calculate the convex hull for any N dimensional space and calculate the area/volume for you as well. See the example and return value attributes towards the bottom of the page for details.

Categories