I have a set of points and i want to draw a curve which should be approximated to original curve.
Let say ,in hawk-eye system(used in cricket) i have a set ofco-ordinates of ball during the entire flight of ball , now how can i draw such a curve going through ball's space co-ordinates and looks appromixately to original curve
one method i thought its to get a large number of points such that every two point
is very close to each other and then draw a straight light between them
Curves are almost always rendered in four steps:
Approximate or interpolate a set of points using a curve or spline algorithm. Choices may include:
Cubic splines, which pass through all of the data points and produce a smooth curve
Bézier curves, which do not pass through all the points, but which lie within the envelope of the consecutive groups of 4 points surrounding each curve section.
Hermite curves, which are defined by a set of points, and a set of tangent vectors: you would need to generate the set of tangent vectors somehow in order to use this sort of curve.
(and probably more that I've forgotten)
Convert whichever representation you chose to a Bézier Curve: this can be achieved by a simple matrix transformation from other curve types.
Repeatedly subdivide the Bézier curve: the control points tend to approximate the curve.
Draw the control points of the subdivided curve, joined by a straight line.
If you go straight for the Bézier curve, which is probably the easiest, then there are some very simple and elegant methods of subdividing it.
I highly recommend Catmull-Rom splines for this purpose, they are based on Hermite curves. Rather than using 2 points and 2 tangents, it uses the four adjacent data points to interpolate making it better suited/simpler for motion path upsampling.
Related
For a curve, I wanna move the start and end point to new position, and then how to keep the shape of the curve ?
From the points which circulated on the yellow curve, move them to red curve position which circulated on the red curve, how to keep the shape of the curve on the red curve ?
When you define spline curve you need to define also tangents angles at endpoints, when you move you points to center, you are chenging the slopes of side lines, so if tangent angles are fixed wrt lines, they will make curve change. If you will see carefully corner angles are same on both images. To keep your curves shape you need to change these angles according side lines slope chenges.
So, let me summarize what you want to do here: given a Bezier curve or a B-spline curve and two new locations for the start point and end point, find a new Bezier/B-spline curve that more or less keeps the same shape as original curve.
One way to achieve this is to find a transformation that would transform the start/end points to their new locations, then you can apply the same transformation to all the other control points for the curve. Basically, this is the same as finding the transformation between a line defined by the curve's start point P and end point Q and another line defined by the new point locations P* and Q*. From P and P*, we can find a translation vector. From line PQ and line PQ, we can find a rotation angle. From length |PO| and length |PQ| we can find a scale factor. So, combining the translation vector, rotation angle and the scale factor, we will be able to find the transformation matrix. Apply the transformation matrix onto all the other control points, then you should be able to get the new curve that more or less maintain the same shape as original curve.
If what you really wan to do is to offset the curves, then this is a totally different story. Offset curves are achieved by a far-more complex algorithm (which I will not elaborate here) and we will specify offset distance (could be positive or negative to imply outwards/inwards offset) instead of new locations for the start/end points.
In my current c++ program I am dealing with a plane that is intersected by several other planes. I want to find the polygon formed by the lines that define the intersections of the planes. For simplicity and computation speed, it seems like my best bet is to get the lines that form the intersections and then work out the polygon in 2d on the surface of the plane. Does anyone have an idea how to translate the lines(represented by a position and a direction vector) onto the plane and the final polygon back into 3d?
In general, this isn't possible to do. The simplest counterexample is the intersection of two planes where the two centers overlap. Viewing it edge-on, it would look like a plus sign. There is no polygon that results from this intersection; a line segment, yes, but no polygon. If you want to draw the resulting polygon, then it needs to be convex, as well which puts more constraints on the allowable intersection configurations.
I'm trying to convert a polygonal 3D mesh into a series of topographic curves that represent the part of the mesh at a specific height for every interval. So far, I've come up with the idea to intersect a horizontal plane with the mesh and get the intersection curve(s). So for this mesh:
I'd intersect a plane repeatedly at a set interval of precision:
and etc.
While this is straightforward to do visually and in a CAD application, I'm completely lost doing this programmatically. How could I achieve calculating this in a programming environment/ what algorithms can I look into to achieve this?
I'm programming in an STL C++ environment (with Boost), loading .obj meshes with this simple loader, and need simple cartesian 2D points to define the output curve.
An option is to process all the faces in turn and for every face determine the horizontal planes that traverses them. For a given plane and face, check all four vertexes in turn and find the changes of sign (of Zvertex - Zplane). There will be exactly two such changes, defining an edge that belongs to a level curve. (Exceptionally you can find four changes of sign, which occurs when the facet isn't planar - join the points in pairs.)
Every time you find an intersection point, you tag it with the (unique) index of the plane and the (unique) index of the edge that was intersected; you also tag it with the index of the other edge that was intersected in that face.
By sorting on the plane index, you can group the intersections per plane.
For a given plane, using a hash table, you can follow the chain of intersections, from edge to edge.
This gives you the desired set of curves.
Can someone tell me the best way to estimate the normal at a point on CAD STL geometry?
This is not exactly a question on code, but rather about efficiency and approach.
I have used an approach in which I compare the point whose normal needs to be estimated with all the triangles in the mesh and check to see if it lies inside the triangle using the barycentric coordinates test. (If the value of each barycentric coordinate lies between 0 and 1, the point lies inside.) This post explains it
https://math.stackexchange.com/questions/4322/check-whether-a-point-is-within-a-3d-triangle
Then I compute the normal of that triangle to get the point normal.
The problem with my approach is that, if I have some 1000 points, and if the mesh has say, 500 triangles, that would mean doing some 500X1000 checks. This takes a lot of time.
Is there an efficient data structure or approach I could use, to pinpoint the right triangle? Or a library that could get the work done?
A relatively easy solution is by using a grid: decompose the space in a 3D array of voxels, and for every voxel keep a list of the triangles that interfere with it.
By interfere, I mean that there is a nonempty intersection between the voxel and the bounding box of the triangle. (When you know the bounding box, it is straight forward to tell what voxels it covers.)
When you want to test a point, find the voxel it belongs to and compare to the list of triangles. You will achieve a speedup equal to N/M, where M is the average number of triangles per voxel.
The voxel size should be chosen carefully. Too small will result in a too big data structure; too large will make the method ineffective. If possible, adjust to "a few" triangles per voxel. (Use the average triangle size - square root of double area - as a starting value.)
For better efficiency, you can compute the exact intersections between the triangles and the voxels, using a 3D polygon clipping algorithm (rather than a mere bounding box test), but this is more complex to implement.
Here is another geometric problem:
I have created an 3-dimensional triangulated iso-surface of a point cloud using the marching cubes algorithm. Then I intersect this iso-surface with a plane and get a number of line segments that represent the contour lines of the intersection.
Is there any possibility to sort the vertices of these line segments clockwise so that I can draw them as a closed path and do a flood fill?
Thanks in advance!
It depends on how complex your isosurface is, but the simplest thing I can think of that might work is:
For each point, project to the plane. This will give you a set of points in 2d.
Make sure these are centered, via a translation to the centroid or center of the bounding box.
For each 2d point, run atan2 and get an angle. atan2 just puts things in the correct quadrant.
Order by that angle
If your isosurface/plane is monotonically increasing in angle around the centroid, then this will work fine. If not, then you might need to find the 2 nearest neighbors to each point in the plane, and hope that that makes a simple loop. In face, the simple loop idea might be simpler, because you don't need to project and you don't need to compute angles - just do everything in 3d.