- Home /
Connect 2 verticies
Hi there! A need to connect red and blue vertecies, by creating additional triangles.
So first thing I do, is get their positions; p1r, p2b Then, I calculate direction vector; _directin = p2b - p1r
Next step, I need to create new vertex in that edge I marked as green. I here I'm clueless how to proced.
Red vertex shares 4 triangles, I can get them, but I need to: 1. Determine, which triangle I need to use 2. And find new vertex position on the edge which is closes to the other blue vertex
And advice on how should I handle it?
I though of comparing vertices by their world positions, then get edge world position, somehow interpolate where new vertex should be put, then create it using TransformInverse, but maybe I can do it more efficiently, using some clever trigonometry or other solution I'm not aware of.
Actually I realized, that I can abstract from 3D and do 2D/2D line intersection test here, one line segment is p1r p2b, other that green edge. Hopefulyl will work out, so I'll try code it in this direction right now
Well, that only works if the mesh is completely flat, otherwise the two lines wouldn't intersect.
Thank you, seems like now I managed to sort it all out in my head, and will proceed just with plain coding. Google helped to me to find info how to handle all kind of different line/line situations
Answer by Bunny83 · Mar 22, 2013 at 03:57 PM
Well, if it's a fully shared mesh it's very easy. Just determine all triangles which use the red vertex and the blue vertex. The red has 4 triangles the blue has 5. Just iterate through the red triangles and compare the other two vertices for each triangle with the outer vertices of the blue triangles. There are exact 3 triangle pairs which share at least one vertex with each other. Just pick the one where both outer vertices match.
This can be done entirely with the triangle list. So just compare the integer values.
If the vertices are not shared it's getting mor complicated. You have to compare them on a position base since neighbor triangles aren't connected. Never direct compare positions, always use an approximation.
Some additional hints:
To get the triangle index of a vertex index, divide the triangle index by 3.
The vertex indices of a triangle are:
// C#
int triangleIndex;
int vert0 = triangleIndex*3 + 0;
int vert1 = triangleIndex*3 + 1;
int vert2 = triangleIndex*3 + 2;
Your answer
Follow this Question
Related Questions
How to get to know a mesh' faces normals? 0 Answers
Vertex color by face 1 Answer
Select a face of an object ingame 3 Answers