I am trying to execute the following in OpenGL: There are 2 3D points p1 and p2, let's say at positions (-1,0,0) and (1,0,0). A 3D line is drawn through both points. Let's say the direction vectors for both the lines are (0,0,1) to begin with. I want to track the points of minimum distance between the two lines and display them as these lines are rotated about the points p1 and p2 about random axes by small angles.
I am new to OpenGL and quite confused about where the computation of nearest points between lines should be carried out. If I draw the two lines by providing end points, I cannot do the computation in the geometry shader as it only has access to one primitive, while I need both lines to calculate the closest points.
How should I proceed with this?
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.
Hi I'm trying to do the Ex 6.5 from Szeliski's book ... But I'm stuck at points 3 and 4, I have the theory of what a vanishing point is, but what does it mean to find it for each face? and how about the focal lenght and rotation angle for those VP? If you can provide some resources easy to understand I will appreciate it.
Thanks!
Vanishing points are points at which parallel lines in a plane approach the same point. So in order to find the vanishing points you would take lines from the plane that are parallel (there are 6 of these per face on a Rubik's cube, 3 in 2 different directions) then where those lines intersect in the image is where a vanishing point is for that plane. You should be able to find 2 vanishing points per face unless you're looking at the cube head on.
You are bit mistaken in saying " the focal length and rotation angle for those VP", the book wants you to find these FROM the vanishing points. After you've found these vanishing points using the other points from the face you can construct a plane (in the coordinate system it would be a single vector normal to the plane). The rotation angle for this would be the difference between the image plane and the plane of the face.
Unfortunately I'm not well versed in finding focal lengths. But there should be a way of determining focal length of the camera by knowing the actual distance between the cubes. You could try reading this: http://www.cs.umd.edu/class/spring2013/cmsc426/lectures/camera-calibration.pdf from an image processing class I took.
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.