Fitting a 3d points of an arc to a circle (regression in Python) - 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

Related

Find intersection between a 3D mesh and a line given by a sequence of point, using 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!!

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

Calculate 3D Plane that Rests on a 3D Surface

I have about 300,000 points defining my 3D surface. I would like to know if I dropped a infinitely stiff sheet onto my 3D surface, what the equation of that plane would be. I know I need to find the 3 points the sheet would rest on as that defines a plane, but I'm not sure how to find my 3 points out of the ~300,000. You can assume this 3D surface is very bumpy and that this sheet will most likely lie on 3 "hills".
Edit: Some more background knowledge. This is point cloud data for a scan of a 3D surface which is nearly flat. What I would like to know is how this object would rest if I flipped it over and put it on a completely flat surface. I realize that this surface may be able to rest on the table in various different ways depending on the density and thickness of the object but you can assume the number of ways is finite and I would like to know all of the different ways just in case.
Edit: After looking at some point cloud libraries I'm thinking of doing something like computing the curvature using a kd tree (using SciPy) and only looking at regions that have a negative curvature and then there should be 3+ regions with negative curvature so some combinatorics + iterations should give the correct 3 points for the plane(s).

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.

Categories