I'm using THREE.JS and I have a this mesh with different surfaces. Of each surface I got its vertices. Now I want to create edges ( connect the vertices with lines). The vertices are in an arbitrary order, so I can't simply connect v1 with v2, v2 with v3 and so on. I think I have to walk through them with a ray clockwise or counter clockwise and put them in the right order somehow and I have to somehow check their distances, so that the horizontal line between the inner vertices doesn't appear, rather it should go right along the real edges,but I don't know how... Any idea?
(the spheres are the vertices that are the real corners of the surface, the orange lines are the wrong edges that need to be corrected and the blue lines are the edges of each single face)
I need to create these 8 edges (red)
Assuming that you are able to assign a unique number to the vertices and to uniquely associate every triangle to a face, and that the triangulation is watertight, the edges of a face are those edges that are common to a triangle of that face and a triangle of another. When you have all edges of a face, it is a trivial matter to chain them in a polygon.
Related
When I compute the difference between two shapes which touches one another (for example a rectangle A in a bigger rectangle B with a hole at rectangle A) and a clip shape (rectangle C) the two touching shapes are merged because their share the same edges and then the clipping is executed.
Is it possible to avoid merging touching shapes when clipping?
Here is an example of the difference between two shapes (A in green and B in red) and a clip (so the operation is: A & B - Clip), it returns the blue shape:
Instead of the blue rectangle, I would like to have those two shapes:
And the intersection would give:
This would give me the four shapes I want:
I know I could perform the operations on each shape separately, but I am afraid it will be more costly.
Note
Here is the result of a XOR:
In the hand I compute the operation myself:
compute the intersections between edges (of the clip shape and other shapes).
for each vertex: sort its edges by angle (mandatory)
walk through each edge clockwise and counterclockwise to compute the new polygons with their holes
This is efficient enough, but I need a space-partitioning data structure to sort edges and quickly their intersections.
Given two points (vertices), say i and j represented by small circles. How can I draw an arc (arrow) connecting those two vertices in Javafx 8? Surprisingly, very little information exists on drawing arcs in javafx8.
Given two points,(vertices), say i and j and a number of arcs between the two vertices. For each arc a direction is given. So for example, I can have 2 arcs from i to j, and 1 arc from j to i. How can I draw these arcs in javafx 8 such that they don't overlap each other. I was thinking on drawing each arc as half of an oval.
Normally I would provide sample code, but here I really have no clue how to draw an arc in between two points in Javafx?
Here is an example of something I would like to draw:
In my application I know the exact coordinates for the vertices a,b,c,d. I just need to know how to draw the arcs (I would favor a faster, simple solution over a pretty solution).
A line drawing is like a graph but its vertices have x,y position. There are no crossing edges. For example, a line drawing like this is a line drawing with 13 vertices numbered by 0-12. A face is a cycle that doesn't have a path that 'inside' it. Faces in the example would be
(0,1,3,2,0), (2,3,5,4,2), (4,5,8,7,4), (7,8,12,11,7) and (0,2,4,7,11,10,9,6,0)
The cycle (0,1,3,5,4,2,0) is NOT a face because there is a path that located inside it, named (2,3). Cycle (0,1,3,5,8,12,11,10,9,6,0) is also NOT a face because there is a path (0,2,4,7,11), located inside it. What algorithm can I use to identify faces like the ones in the example?
Assume all your edges are line segments; every planar graph can be drawn using only line segments. Also assume the graph is connected. Now the algorithm is pretty simple:
Construct a directed graph, such that the vertices are same as in the original graph and there's two directed edges for every original edge, one in each direction
Start with a random (directed) edge that's not been used yet. At its end, choose the next outgoing edge clockwise (or counterclockwise will do as well, just always the same). To decide which edge that is, you'll have to compute from the coordinates of vertices in the planar embedding. You'd better precompute this edge order for each vertex beforehand.
Keep doing that with the end of the selected edge, until you reach the starting vertex. At that point, you've completed a face.
When there's no unused edges, you've found all faces in the graph
Or, use a library like Boost, that has an efficient implementation of such task
There are two kinds of surface mesh models, closed mesh like a sphere or a cube and the second one is the open mesh model which means the surface of the model is not in a closed loop. It is open from somewhere like a hollow pipe.
Sp what I want is I want to detect the border vertices of the open mesh model. there is no border in closed loop mesh but in open mesh we have to detect border vertices for some smoothing, subdivision, etc. operations.
Kindly, suggest me how can I select/detect border vertices ? what is the optimal way to do this ?
by comparing edges of the triangles ? Give me some idea ?
Thanks.
Assuming that you have a manifold mesh, then the border of the mesh are those edges which belong to only one polygon. Edges that are not on the border will belong to two polygons. The border vertices are the vertices that belong to the border edges.
A naive way to find the border vertices is to iterate through all your edges, count how many polygons they belong to, and if they only belong to one polygon, then collect the edge's vertices as border vertices. You will have to remove duplicates vertices from your collection, though.
A second approach is to have your mesh data structure examine each edge as they are added to the mesh, or as polygons are attached to particular edges. In this way, the mesh data structure can keep a list of up-to-date border edges for you, so that when you needed the edges you would not have to find them each time. This will greatly reduce the overhead of determining border edges, although inserting edges and polygons will be slightly more expensive. Your mesh data structure will also take up a bit more memory.
Assuming that your mesh is a 2D (or 2.5D) regular, well-constructed triangulation. You can use some of the properties listed here: http://graphics.stanford.edu/courses/cs468-10-fall/LectureSlides/02_Basics.pdf
Page 9 defines the degree (or valence) of a vertex as the number of incident edges. As shown, all boundary vertices 4 incident edges. "Internal" vertices have 5 incident edges.
Page 17 defines a boundary edge as one that is adjacent to exactly one face.
You might find the discussion on page 22 helpful (closed 2-manifold triangle meshes)
Given a convex polygon represented by a set of vertices (we can assume they're in counter-clockwise order), how can this polygon be broken down into a set of right triangles whose legs are aligned with the X- and Y-axes?
Since I probably lack some math terminology, "legs" are what I'm calling those two lines that are not the hypotenuse (apologies in advance if I've stabbed math jargon in the face--brief corrections are extra credit).
I'm not sure about writing an algorithm to do this but it seems entirely possible to do this for any convex polygon on a piece of paper. For each vertex project a line vertically or horizontally from that vertex until it meets another of these vertical or horizontal lines. For vertices with small changes in angle, where adjacent sides are both travelling in the same direction in terms of x and y, you will need to add two lines from the vertex, one horizontal and one vetical.
Once you have done this, you should be left with a polygon in the centre of the origonal polygon but with sides that are either vertical or horizontal because the sides have been formed by the lines drawn from the vertices of the original polygon. Because these sides are either vertical or horizontal, this shape can easily be sub-divided into a number of triangles with one horizontal side, one vertical side and one hypotenuse.
I'm assuming you've already ordered the vertices as you describe above, and that they indeed define a convex polygon.
Each vertex defines a horizontal line. For V vertices, then, you will have a set of V lines. Discard any line that meets one of the following criteria:
The vertex or vertices defining that line has/have the highest or lowest Y component (if one vertex, that line intersects the polygon only at that point; if two, that line coincides with a polygon edge)
If two vertices have equal Y coordinates otherwise, keep only one of those lines (it's duplicated).
The result will resemble a "banding" of the polygon.
Each horizontal line intersects the polygon at two points. One is its defining vertex. The other is either another vertex, or a point on a segment defined by two vertices. You can determine which is the case easily enough - just simple comparison of Y coords. The coordinates of the intersection with a segment is also easy math, which I leave to you.
Each intersection defines a vertical segment. The segment is contained within the polygon (if it coincides with an edge, you can discard it), and the other end meets either another horizontal line, or the edge of the polygon if that edge is itself horizontal. Determining the case is again a matter of mere comparison of coords. Finally, there may be 0-2 additional vertical segments, defined by the vertices with the highest and/or lowest Y coords, if there is only one of either.
The resulting diagram now shows each band with a right triangle trimmed off each end if possible. Each triangle should meet your criteria. The leftover regions are rectangles; draw an arbitrary diagonal to split each into two more right triangles meeting your criteria.
You're done.
I'm not sure if this is possible. Think about a square that's already aligned with the sides on the X and Y axes. How do you draw triangles using the vertices that are also aligned to the X,Y axes?
Or are the actual sides of the polygon allowed to be along the x,y axis. Which means you could just draw a line down the diagonal of the square. If so, it might be difficult to do with a more complex polygon where some sides are aligned to the axes, while others are not.
I'm not convinced there is a general solution to the question as posed. The problem is the aligned with the X- and Y-axes bit. That means that each vertex needs to be projected to the opposite side of the polygon in both the X and Y directions, and new vertices created at those intersection points. But that process must continue on for each new vertex added that way. You might get lucky and have this process terminate (because there's already a vertex appropriately placed on the opposite side), but in the general case it's just going to go on and on.
If you throw out that restriction, then Neil N's suggestion seems good to me.
Neil N is right, I think. Unfortunate that he didn't provide any specific links.
If you have a trapezoid whose top and bottom are parallel to the X axis, you can easily render that with 4 right triangles. Call that shape a horizontal trapezoid.
If you have a triangle with one side parallel to the X axis, you can render that with 2 right triangles -- or you can consider a degenerate case of the trapezoid with the top of bottom having length zero.
Start at either the top or bottom of your convex hull (i.e. search for coordinate with min or max y) and split it into horizontal trapezoids.
It's not to hard to write the code so that it works just as well with non-convex polygons.
I think this is not possible in the general case.
Consider the polygon {(0, 1), (1, 0), (2, 0)}
.
..
This triangle can not be split into a finite number of triangles as you describe.