Part III: Creating and Implementing Operators



Return to the Project 2 Home Page


Operators:

Download the zip.

Specification:

Implement the .n, .p, .o, .l, .r, .v, .g operators. Enable the user to click close to a corner on a triangle and draw a small ball there. Then provide ways of moving the dot by pressing keys to use those operators.

Description:

Whenever the user clicks near a corner of a triangle, a small red ball is created in that corner. By pressing the following keys, the user can traverse the entire e triangle mesh:

'N' = Next

'P' = Previous

'O' = Opposite

'L' = Left

'R' = Right

Extra Credit: 'U' = Undo last Triangle

Detailed Explanations:

One of the problems we cam across was that we could not figure out how to calculate whenever the user clicked inside of a triangle - and how to determine which triangle had been clicked. This information was necessary whenever we needed to draw the ball inside of the triangle to do the different operations on it. So, to solve this problem, We used the same idea as used to determine the orientation of a triangle.

In class, we talked about determining the orientation of the triangle, and found that to check this, you had to use:

((c.n.v.g - c.v.g) x (c.p.v.g - c.v.g)) dot (0,0,1) > 0
If true, this means that the triangle is properly oriented so that the user is not looking behind the given triangle. So, using this knowledge, suppose you have a triangle, A,B,C and you clicked at a point f. To find out if f lies within the triangle, you need to find the following:

dot(cross(subtract(g[A], f), subtract(g[B], f)), (0,0,1)) > 0
You do this for each of the vectors, AB, BC, CA and if all three are true, then you know that you are within a triangle. This determines if the clicked vertex is within the boundary of the triangle at a given point. This algorithm was necessary in determining the location of a mouse click, which was used to place the ball at the different locations in the corners.

For the image below you could think of the points being P1, P2, and P3. The user could either click at Q or P and this algorithm would enable us to determine where they had clicked, and thereby what triangle and corner they had chosen.

http://graphics.cs.ucdavis.edu/CAGDNotes/Affine-Barycentric-and-Convex/Affine-Barycentric-and-Convex.html

Examples of the Operators:

The original corner that was clicked, note that the dot does not appear exactly at the vertex, but it appears close to it.


The corner.n which returns the next corner.


The corner.p which returns the previous corner from the original.


The corner.l which returns the c.p.o of the original corner.


The corner.r which returns the c.n.o of the original corner.


The corner.o which returns the opposite of the original corner, or the triangle which shares the same two other vertices.


Conclusions:

Once we figured out how to determine when the user clicks on the inside of a triangle, we were able to properly represent the different operations. With a mixture of all of the operations, the user could traverse the entire mesh, visiting each corner of each triangle and each of their neighbors. The opposite operation especially aided us in determining the orientation of the triangles, which wouldn't be accessed without the proper triangular orientation. Each of these operations will be very useful to us in future parts of this project because they will aid us in smoothing the meshes. It will be faster to determine neighbors than it would have been to access each individual "corner".