learning - Academic Conferences Limited

learning - Academic Conferences Limited learning - Academic Conferences Limited

academic.conferences.org
from academic.conferences.org More from this publisher
27.06.2013 Views

Robert Lucas Occasionally we will also refer to 2 vectors that are used to map textures onto surfaces. In both cases vectors are represented by a bold letter, such as V1 in any formula or sentence. 3. Basic data structures In the Unity (Unity 2011) world a mesh consists of an array of triangles. This is a list of indices into another array of vertices where each vertex is a 3-vector. This defines the position of the vertex in 3D space. Each consecutive three entries of the triangles array define a triangle. To make this tangible figure 2 shows how a cube is represented by twelve triangles where each triangle consists of three vertices. The ‘triangles’ array that corresponds to this contains: 3, 1, 2, 2, 1, 0, 5, 3, 4, 4, 3, 2, 7, 5, 6, 6, 5, 4, 1, 7, 0, 0, 7, 6, 5, 7, 3, 3, 7, 1, 2, 0, 4, 4, 0, 6. In fact, it is not quite as simple as this as there is a good deal of redundancy in the vertices array with the same point being represented as many times as it appears in the definition of a triangle. The very first operation applied in our cutting process is to remove this redundancy to make the triangles array as defined above. This makes it very much easier to compare vertices as the vertex number in the triangles array uniquely defines a point in space. Thus if two entries in the triangles array are the same, then they must refer to the same point in 3D space. Figure 2: The vertices of a cube drawn as a mesh of triangles 4. Developing a cutting algorithm Developing software for complex operations can sometimes be rather akin to the old joke: when you ask an Irishman the way, he replies ‘Well I wouldn’t want to start from here’. This is because the space the problem spans can just be too large to get to grips with. However much we like to pretend in the software world that all things can be achieved by a top-down design approach (Lucas 2000), in practice we commonly use a combination of top-down and bottom up design approaches, if for no other reason than it can prevent us going insane from the complexity of what we are trying to deal with. The bottom-up approach does allow us to start from ‘somewhere else’ which will indeed make it easier to get to our destination. 4.1 Representing a planar cut as a data structure In this case it seems sensible to start with a definition of a cut as a data structure that will give us a handle on actually performing the cut. Then we can address the issue of how we might create such a cut data structure at a later time when we are entirely happy that our representation has made the problem tractable. This concentrates the mind wonderfully, what do we mean by a cut? What do we want to be the result of the cut? These questions come to mind as soon as we address the problem of representing the cut. For simplicity we will consider planar cuts. Elementary geometry tells us that a plane can be represented by a normal to the plane and a single point on the plane, so there is certainly no problem in representing that; two 3-vectors will suffice. If we look at Figure 3 and imagine a planar cut caused by a blade occupying a plane containing the x and y axes passing through the 436

Robert Lucas origin at the centre of the cube, we can imagine the points of intersection of this plane with each affected triangle. Figure 3: Visualizing the cut points of a plane with a cube This gives us the necessary insight to define a cut-point as consisting of two vertices and a number representing how far from the first vertex toward the second is this cut-point. Thus a single cut point is represented by the triple: (VertexA, VertexB, lambda) Where the cut occurs on this edge between VertexA and VertexB at the point (VectorB-VectorA)* lambda Where VectorA is the vector from the origin to VertexA and VectorB is the vector from the origin to VertexB. Thus the entire planar cut can then be represented by the ordered list: {CutA, CutB,…,CutH} It is clearly the case that this representation can be used on any arbitrary complicated mesh, just as long as the mesh is composed of triangles. More importantly, we can now perceive how a cutting algorithm might proceed by taking each cut point and creating a vertex at the point of the cut and rebuilding each triangle that has a vertex on the edge containing the cut point. Finally we will need to fill in the missing faces that the cut has created. In pseudo code (Lucas 2000) the algorithm is: Begin CutPoint1 = Cut[0] VertexA = CreateVertex(CutPoint1) For each remaining cut point do CutPoint2 = Cuts[next]; VertexB = CreateVertex(CutPoint[next]) If both cut points share same first vertex then CreateTriangle(VertexA, VertexB, SharedVertex) Else CreateTriangle(VertexA, VertexB, CutPoint1.StartVertex) CreateTriangle(VertexA, CutPoint2.StartVertex, CutPoint1.StartVertex) Endif VertexA = VertexB Repeat End 437

Robert Lucas<br />

Occasionally we will also refer to 2 vectors that are used to map textures onto surfaces. In both cases<br />

vectors are represented by a bold letter, such as V1 in any formula or sentence.<br />

3. Basic data structures<br />

In the Unity (Unity 2011) world a mesh consists of an array of triangles. This is a list of indices into<br />

another array of vertices where each vertex is a 3-vector. This defines the position of the vertex in 3D<br />

space. Each consecutive three entries of the triangles array define a triangle. To make this tangible<br />

figure 2 shows how a cube is represented by twelve triangles where each triangle consists of three<br />

vertices. The ‘triangles’ array that corresponds to this contains: 3, 1, 2, 2, 1, 0, 5, 3, 4, 4, 3, 2, 7, 5, 6,<br />

6, 5, 4, 1, 7, 0, 0, 7, 6, 5, 7, 3, 3, 7, 1, 2, 0, 4, 4, 0, 6. In fact, it is not quite as simple as this as there is<br />

a good deal of redundancy in the vertices array with the same point being represented as many times<br />

as it appears in the definition of a triangle. The very first operation applied in our cutting process is to<br />

remove this redundancy to make the triangles array as defined above. This makes it very much easier<br />

to compare vertices as the vertex number in the triangles array uniquely defines a point in space.<br />

Thus if two entries in the triangles array are the same, then they must refer to the same point in 3D<br />

space.<br />

Figure 2: The vertices of a cube drawn as a mesh of triangles<br />

4. Developing a cutting algorithm<br />

Developing software for complex operations can sometimes be rather akin to the old joke: when you<br />

ask an Irishman the way, he replies ‘Well I wouldn’t want to start from here’. This is because the<br />

space the problem spans can just be too large to get to grips with. However much we like to pretend<br />

in the software world that all things can be achieved by a top-down design approach (Lucas 2000), in<br />

practice we commonly use a combination of top-down and bottom up design approaches, if for no<br />

other reason than it can prevent us going insane from the complexity of what we are trying to deal<br />

with. The bottom-up approach does allow us to start from ‘somewhere else’ which will indeed make it<br />

easier to get to our destination.<br />

4.1 Representing a planar cut as a data structure<br />

In this case it seems sensible to start with a definition of a cut as a data structure that will give us a<br />

handle on actually performing the cut. Then we can address the issue of how we might create such a<br />

cut data structure at a later time when we are entirely happy that our representation has made the<br />

problem tractable. This concentrates the mind wonderfully, what do we mean by a cut? What do we<br />

want to be the result of the cut? These questions come to mind as soon as we address the problem of<br />

representing the cut. For simplicity we will consider planar cuts. Elementary geometry tells us that a<br />

plane can be represented by a normal to the plane and a single point on the plane, so there is<br />

certainly no problem in representing that; two 3-vectors will suffice. If we look at Figure 3 and imagine<br />

a planar cut caused by a blade occupying a plane containing the x and y axes passing through the<br />

436

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!