• No results found

Collision detection for trimming curves and BREPs Alexander Östman Report Department of Physics April 19, 2014 Umeå University

N/A
N/A
Protected

Academic year: 2021

Share "Collision detection for trimming curves and BREPs Alexander Östman Report Department of Physics April 19, 2014 Umeå University"

Copied!
57
0
0

Loading.... (view fulltext now)

Full text

(1)

Report

Collision detection for trimming curves and BREPs

Alexander Östman

Master Thesis Project Supervisor: Michael Brandl

(2)
(3)

Abstract

This report treats the implementation of collision detection algorithms for Boundary representations (BREPs) consisting of connected trimmed surfaces, mainly Non Uniform Rational Basis Spline (NURBS) surfaces. Using the OpenNurbs software package, complicated geometries created in CAD program Space Claim were imported to the physics engine AgX, where dynamic simulations were carried out. Collision detection algorithms for the geometry pairs BREP-line, BREP-plane and BREP-sphere have been developed and investigated. In the case of BREP-sphere collision detection, experiments have been carried out which show that BREP-shape representation exceeds trimesh-shape representation both in computational performance and in collision accuracy. The conclusion is that BREP representation has the potential to replace trimesh representation for some complex geometries with higher computational performance and more accurate simulations as a result.

(4)
(5)

Sammanfattning

I den här rapporten behandlas implementation av kollisions detekterings algoritmer för Boundary Represenations (BREPs), som består av sammansatta trimmade ytor, huvudsakligen Non Uniform Rational Basis Spline (NURBS) ytor. Genom att använda OpenNurbs mjukvaru-paket kunde komplicerade geometries som skapats i CAD programmet Space Claim läsas in i fysik motorn AgX, där dynamiska simulationer utfördes. Kollisions detekterings algoritmer för geometriparen BREP-linje, BREP-plan och BREP-sfär har utvecklats och undersökts. I fallet BREP-sfär har experiment utförts som visar att BREP-form representationen överstiger trimesh-form representationen både i datakraft och i att finna korrekta kollisioner.

(6)
(7)

Content

ABSTRACT ... 3 CONTENT ... 7 GLOSSARY ... 9 1. INTRODUCTION ... 11 1.1. BACKGROUND ... 11 1.2. AIM ... 11 1.3. RELATED WORK ... 11

1.3.1. Ray tracing of Non Uniform Rational Basis Splines (NURBS) ... 11

1.3.2. Boundary representation and Constructive Solid Geometry ... 12

1.3.3. Collision detection for NURBS ... 12

2. THEORY ... 13

2.1. SURFACE AND CURVE THEORY ... 13

2.1.1. Basics ... 13

2.1.2. Basis splines ... 14

2.1.3. Basis function ... 15

2.1.4. Non Uniform Rational Basis Splines (NURBS) curves ... 15

2.1.5. Non Uniform Rational Basis Splines (NURBS) Surfaces ... 16

2.1.6. Trimming curves... 17

2.1.7. Newton-Raphson method ... 18

2.2. BOUNDARY REPRESENTATION THEORY ... 18

2.2.1. Basics ... 18

2.2.2. Construction ... 19

2.3. COLLISION DETECTION THEORY ... 20

2.3.1. Basics ... 20 2.3.2. Queries ... 20 2.3.3. Geometries ... 20 2.3.4. Intersection detection ... 20 2.4. PHYSICS ENGINE ... 21 2.4.1. Basics ... 21 2.4.2. AgX ... 21 3. STUDIES ... 23 3.1. OPENNURBS ... 23

3.2. SPACECLAIM MODELS ... 23

4. ALGORITHMS ... 25

4.1. GEOMETRIC SPECIFIC ALGORITHMS ... 25

4.2. GENERAL ALGORITHMS ... 25

4.2.1. Finding horizontal and vertical tangents to a trimming curve ... 25

4.2.2. Test to determine if a contact-point should be trimmed away ... 26

4.2.3. Searching contact-points over a curve ... 27

5. EXPERIMENTS ... 29

5.1. SPHERICAL BALL JOINT EXPERIMENT ... 29

5.2. SHIFT GATE EXPERIMENT ... 30

5.3. FUNCTIONALITY TESTS ... 31

6. RESULTS ... 33

6.1. SPHERICAL BALL JOINT EXPERIMENT ... 33

6.2. SHIFT GATE EXPERIMENT ... 35

6.3. FUNCTIONALITY TESTS ... 41

7. DISCUSSION ... 51

(8)

9. ACKNOWLEDGMENTS ... 55 10. REFERENCES ... 57

(9)

Glossary

AABB: Axis Aligned Bounding Box, rectangular box, faces oriented such a way that its face normals are at all times parallel with the coordinate axis.

AgX Multiphysics: A physics engine. A posteriori detection: after collision occurs. A priori detection: before collision occurs.

Arc curves: A curve defined by a radius and an angle.

BREP: Boundary representation, a solid is represented as a collection of connected surface elements, the boundary between solid and non-solid.

BV: Bounding volume, a simple volume encapsulating one or more objects. BVH: Bounding volume hierarchy, a tree of arranged bounding volumes. C++: A programming language.

CAD: Computer Aided Design, the use of computer systems to assist in the creation, modification, analysis, or optimization of a design.

CAE: Computer Aided Engineering, the broad usage of computer software to aid in engineering analysis tasks. CAM: Computer Aided Modeling, the use of computer software to control machine tools and related machinery in the manufacturing of workpieces.

Control Points: determine the shape of NURBS curves.

CSG: Constructive Solid Geometry, a technique in solid modeling to create a complex surface or object by using Boolean operators to combine objects.

Knots: Breakpoints/intervals in a NURBS curve/surface.

Newton-Raphson method: A numerical method to successively find better approximations to the roots of a real-valued function.

NURBS: Non Uniform Rational Basis Splines, a mathematical model used for representing curves and surfaces. OpenNurbs: A free software package for reading and writing NURBS.

Order: Defines the number of nearby control points that influence any given point of a NURBS curve. Penetration depth: The depth in which two objects overlap.

Revolution Surface: a surface defined by a revolute curve, an axis of revolution and an angle. SpaceClaim: A CAD program.

Trimesh: Representation of complex surfaces using triangles.

Trimming Curves: Curves in the 2D parameter space of NURBS surfaces, determines what part of the surface should be trimmed away.

Trimming loop: A set of connected trimming curves.

(10)
(11)

1. Introduction

1.1. Background

Collision detection plays an important role in multiphysics simulation. Collisions between two or more objects have to be detected before they can be resolved. In order to resolve a collision, information about the depth, direction and place of the collision is needed.

Geometrical objects for collision detection are traditionally described with various primitives such as e.g. spheres, planes, cylinders, or triangle meshes. In many areas like computer aided design (CAD), manufacturing (CAM) or engineering (CAE), however most modeling of three-dimensional objects is done using non-uniform rational basis splines (NURBS), a mathematical model which makes it easy to create smooth surfaces. The NURBS surfaces are commonly limited by trimming curves; and the trimmed patches are then connected together in boundary representations (BREPs).

The master thesis is carried out in collaboration with Algoryx Simulation AB1. Algoryx's solutions are based

on contemporary scientific research in multiphysics and high-performance numerical methods and are packed into modern object oriented software solutions.

AgX Dynamics is a next generation physics engine for professional and industrial applications. It is developed to both meet the stability and performance requirements for virtual reality simulators and visual effects, as well as the requirements on realism and precision in engineering applications. AgX supports some collision detection for NURBS, using the free software package OpenNurbs2. AgX is written in the C++

programming language.

1.2. Aim

The aim of this master thesis project is to implement functionality for collision detection between BREPs. In the long term, the goal for Algoryx is to be able to successfully import a set of models created in the CAD software SpaceClaim3 to AgX and be able to perform collision detection on them. However, this thesis will primarily

focus on BREPs constructed from three different kinds of surfaces namely NURBS, plane and revolution surfaces.

The project is divided into the following tasks.

- A study of several models made in SpaceClaim to determine which surface types shall be in focus. - A study of OpenNurbs in order to determine what functions can be used and which approach to take for

further implementations.

- Implementation of the BREP shape-type, explained in section 2.2. - Implementation of trimming curves, explained in section 2.1.

- Implementation of collision detection between BREPs-Lines, BREPs-Spheres, and BREPs-planes.

1.3. Related Work

1.3.1.

Ray tracing of Non Uniform Rational Basis Splines (NURBS)

Ray tracing is a technique for generating images by tracing the path of light through pixels in an image plane and simulating the effects of its encounters with virtual objects. Ray tracing has become one of the most common methods for generating realistic images. Many realistic effects such as penumbrae, motion blur, fog, gloss, translucency and depth of field can be obtained using standard ray tracing. Ray tracing is a special case of collision detection. 4

Non-uniform rational basis splines (NURBS) surfaces are a common way to represent surface meshes in computer aided design (CAD). There are several studies on how to efficiently ray trace NURBS (Martin et al., 2000; Efremov, 2004; Albert, 2005; Valkering, 2010). Trimming curves are a common method for overcoming the topologically rectangular limitations of NURBS surfaces. Almost all possible surface shapes can be modeled using trimmed NURBS surfaces.

Few methods of ray tracing trimmed NURBS surfaces are described in the literature. There are however some studies on how to construct efficient methods of ray tracing trimmed NURBS surfaces (Efremov, 2004).

1

http://www.algoryx.se/

2

http://www.rhino3d.com/opennurbs

3

http://www.spaceclaim.com/en/default.aspx

4

http://en.wikipedia.org/wiki/Ray_tracing_(graphics) (28 March 2014)

(12)

1.3.2.

Boundary representation and Constructive Solid Geometry

Boundary representation (BREP) and Constructive Solid Geometry (CSG) are the most widely used representation schemes of 3D objects. While each scheme possesses its strength and weakness, combining both representations of same object in a strong BREP/CSG structure would allow for solving some problems encountered in computer graphics in a more efficient way. There are not many references in this area, but one is Poutrain (Poutrain et al., 2001).

1.3.3.

Collision detection for NURBS

Previous to this thesis, a thesis work focusing on developing collision detection for NURBS was performed by Martin Häggström for Algoryx. Even though Martin never finished his work, he did manage to implement some collision detection functionality for NURBS in AgX Dynamics. This has been used and adapted in the implementation of collision detection for BREPs.

(13)

2. Theory

2.1. Surface and Curve theory

Unless otherwise stated, following section refers to Piegl & Tiller, 1997.

2.1.1.

Basics

The two most common methods of representing curves and surfaces in geometric modeling are implicit equations and parametric functions.

The implicit equation of a curve in the plane has the form

. (1)

For a given curve the equation is unique up to a multiplicative constant. An example is the circle of unit radius centered at the origin (figure 1), specified by the equation

. (2)

Figure 1, the unit circle, can be defined in implicit form (equation 2) or parametric form

(equation 4, for a quarter circle).

In parametric form, each of the coordinates of a point is represented as an explicit function of an independent parameter

. (3) Where the interval is usually normalized to . The first quadrant of the unit circle is defined by the parametric functions

. (4)

Note that the parametric representation of a curve is not unique. The implicit equation of a surface has the form

(14)

An example is the sphere of unit radius (figure 2) specified by the equation:

. (6)

Figure 2, the unit sphere, can be defined in implicit form (equation 6) or parametric form

(equation 7).

A parametric representation (not unique) of the same sphere is given by:

(7) , , , .

Of the implicit and parametric forms, it is difficult to maintain that one is always more appropriate than the other and successful geometric modeling is done using both techniques. However, the parametric form is more natural for designing and representing shape in a computer and will be used almost exclusively in this thesis.

Curves and surfaces can be subdivided into several different categories. Several of the most common categories of curves/surfaces are implemented in the software package OpenNurbs. After investigating the curve and surface parts of the brepstructure from several for Algoryx interesting 3D-models constructed in SpaceClaim and imported to AgX using OpenNurbs, it was decided that the focus of this master thesis should be on the following curves/surfaces: LineCurves, ArcCurves, NurbsCurves, PlaneSurfaces, RevolutionSurfaces, NurbsSurfaces.

A LineCurve in OpenNurbs is defined as a straight line between two points in either 2D or 3D space. An ArcCurve in OpenNurbs is used to represent arcs and circles. An ArcCurve is defined by a radius and an angle. A PlaneSurface is really a finite rectangle. It stores and intervals of the plane that defines the rectangle, and the domain intervals that specify the evaluation domain. A RevolusionSurface is defined by a Revolute curve and an axis of revolution and an angle. The Revolute curve can be any curve, but in this master thesis only LineCurves and ArcCurves will be considered.

More complex curves and surfaces can be represented in several ways (for example by using high degree polynomials). In this thesis, NurbsCurves/Surfaces will be used, and a more detailed explanation of NurbsCurves follows in below chapters.

2.1.2.

Basis splines

A B-spline (basis spline) is a piecewise polynomial function of degree k in a variable x. It is defined over a range . The points where are known as knots or break-points. A B-spline is a continuous function

at the knots.

A pth degree B-spline curve is defined by a set of at least p+1 control points { }, and a set of th degree B-spline basis functions defined on the non-periodic and non-uniform knot vector and has the form

(15)

(8)

where { } are the control points and { } are the B-spline basis functions, described in detail in

subsection 2.1.3

2.1.3.

Basis function

There are a number of ways to define the B-spline basis functions. In this thesis we will consider the deBoor-Cox recurrence formula since it is the most useful for computer implementation.

We define the knot vector to be a nondecreasing sequence of real numbers, where are called knots. The ith B-spline basis function of p-degree denoted by is defined as

(9)

The knot vector divides the parametric space into intervals. The half-open interval [ , ) is called the th

knot span. It can have zero length, since knots need not be distinct. This represents a specific parametric interval. When one or several knot spans have zero length, the knot is said to have the multiplicity of the number of times the knot appears. The multiplicity of a knot affects the continuity of the basis functions. A knot with multiplicity k results in the curve being continuous at that point. Only the relation between the knots matter, i.e. the

knot vectors [1, 3, 5] and [1, 5, 9] is equal. Knot vectors are therefore often normalized; [0,0.5,1].

2.1.4.

Non Uniform Rational Basis Splines (NURBS) curves

NURBS stand for Non Uniform Rational B-Spline. An example of a NURBS curve can be seen in figure 3. In contrast to splines that are only non-rational, NURBS can be rational and is therefore a generalization of B-splines. NURBS have weights associated with each control point. If the weights are not all equal, the curve is rational.

A pth degree NURBS curve is defined by

, (10)

Figure 3, a NURBS curve

where the { } are the control points (forming a control polygon, the { } are the weights and the { } are

the pth degree B-spline basis functions defined on the knot vector (see section 2.1.3). Unless otherwise stated we assume that , and > 0 for all i.

With

, (11)

equation 10 can be rewritten as

(16)

Weights provide further possibilities of customizing the parametric curve which enables NURBS to form shapes that B-splines can not. Weights basically decide how much each control point affects the final curve.

2.1.5.

Non Uniform Rational Basis Splines (NURBS) Surfaces

Equation 10 defining a NURBS curve can easily be extended to define a NURBS surface, with a grid of control points opposed to a line. Each dimension is then defined by a separate knot vector (u, v) and order (p,q). A NURBS surface of degree p in the u direction and q in the v direction is a bivariate vector-valued piecewise rational function of the form

. (13)

The { } form a bidirectional control net, the { } are the weights, and the { } and { } are the

nonrational B-Spline basis functions (see 2.1.3).

Similarly to the surface case, introducing the piecewise rational basis function

(14)

the surface equation 13 can be written as:

(15)

The order of a NURBS curve defines the number of nearby control points that influence any given point on the curve. The curve is represented mathematically by a polynomial of degree one less than the order of the curve. Hence, second-order curves (which are represented by linear polynomials) are called linear curves, third-order curves are called quadratic curves, and fourth-order curves are called cubic curves. The number of control points must be greater than or equal to the order of the curve.

An important property of B-Spline basis functions is the partition of unity (Valkering, 2010).

Combined with the local support property one obtains the strong convex hull property. (Valkering, 2010) This property guarantees that the curve or surface is completely contained in the convex hull of its control points (Piegl & Tiller, 1997).

This means that if the control points is bound within a convex geometry, so is the surface, a property that is very useful for physics engines. In addition, any subsection of the surface is completely contained within the bound defined by its corresponding control points.

(17)

Figure 4, the UV subspace of a NURBS surface

2.1.6.

Trimming curves

A limitation with NURBS surfaces is the fact that the parameter subspace is quadratic. This leads to the surface being defined everywhere between (figure 4). A NURBS surface hence does not

contain any holes, and there are limits to how the edges of the surface can be constructed. To solve this issue, the concept of trimming curves is introduced. A trimming curve is an arbitrary curve (often a NURBS curve) in the 2D parameter space of the NURBS surface (see figure 5). A set of trimming curves are connected together to form a trimming loop. Depending on the orientation of the trimming loop, it can be determined whether or not the part contained inside the trimming loop should be “trimmed away” or not. Generally, everything to the right of a trimming curve should be trimmed away.

(18)

2.1.7.

Newton-Raphson method

The Newton-Raphson method is a method to find successively better approximations to the roots of a real-valued function. In one variable, given a function and its derivative we begin with a first guess for a root of the function. A better approximation is

.

(16)

The process is repeated and we obtain

.

(17)

The method can be extended to multi-variables, using the jacobian matrix. The Newton-Raphson method only guarantees local convergence.

2.2. Boundary Representation theory

2.2.1.

Basics

Unless otherwise stated, following section references to Stroud, 2011.

Boundary representation models of solids have two basic parts: the topology and the geometry, kept separate for practical reasons. The topology defines the structure of the model and the geometry its shape.

The main elements of the topology are faces, edges, vertices, trims and loops. Other elements exist and are used for practical reasons. The loop is necessary to represent multi-connected faces for instance. The topology elements contain information on how the BREP is constructed, which parts are connected, and which parts should be trimmed away.

The geometry contains information of the shape of the BREP, or rather, data of the surfaces and curves defining the BREP. In figure 6 the connections between the topology and geometry is displayed.

Figure 6, topology and geometry of a segment of a BREP (source

http://www.rhino3d.com/opennurbs).

(19)

2.2.2.

Construction

This section attempts to explain the structure and creation of a uniform cubic BREP (figure 7) using OpenNurbs.

Algorithm 1 Construction of uniform cube-shaped BREP

MakeCubeBrep() {

brep = New ON_Brep() //creates new empty BREP For(i = 0; i < vertex.size; i++)

{

brep->NewVertex(vertex[i]) //add each vertex to the BREP }

For(i = 0; i < edge.size; i++) {

CubeEdgeCurve(vertex(i1), vertex(i2)) //create new edge between two vertices MakeCubeEdge(brep, vertex(i1), vertex(i2), edge(i)) //add each edge to the BREP

}

For(i = 0; i < face.size; i++) {

CubeSideSurface(vertex(i1), vertex(i2), vertex(i3), vertex(i4)) //create new surface between four vertices MakeCubeFace(brep, face(i), edge(i1), edge(i2), edge(i3), edge(i4)) //add each surface to the BREP }

}

(20)

2.3. Collision detection theory

Unless otherwise stated, the following section follows Ericson 2005, chapters 2-6.

2.3.1.

Basics

There are several ways one can design a collision detection system. When choosing which approach to take, some factors have to be considered.

- The geometrical representation used for the scene and its objects have a bearing on the algorithms used. Fewer restrictions put on these representations leads to the need of more general collision detection solutions with possible performance repercussions.

- Different kind of queries can be used to test whether or not a collision has occurred or is about to occur. The more detailed query types, the more computational effort required to obtain the results. Not all object representations support all query types. Queries are further described in section 2.3.2.

- Environment simulation parameters. The simulation contains parameters having direct impact on the collision detection system, including the number of objects, their sizes, positions and movement, if they are allowed to interpenetrate and if they are rigid or flexible.

- Performance. Real-time collision detection systems operate under strict time and size restrictions where several features are usually balanced to meet stated performance requirements.

- Robustness. Different applications require different level of physical simulation. Stacking of bricks requires much more sophistication from a collision detection system than bouncing a ball on a plane. The ball bouncing slightly too early or at somewhat larger angle will go unnoticed, but even the slightest errors in computing contact points of stacked bricks is likely to result in them slowly starting to slide off each other.

2.3.2.

Queries

Different kinds of queries are used to answer where a collision has occurred or are imminent. The most straightforward collision query is the interface detection or intersection testing problem answering the boolean question of whether two objects, A and B, are overlapping at their given positions and orientations. Boolean questions are fast to answer and easy to implement. However, sometimes they are not enough and the intersecting parts of the object must be found. Intersection finding is a more difficult problem to solve, involving finding one or more points of contact. For rigid-body simulations the set of contacting points (the contact manifold) may need to be determined. Robustly computing the contact manifold is a difficult problem.

When objects penetrate it might be required to find the penetration depth. The penetration depth is usually defined in terms of the minimum translation distance which is the length of the shortest movement vector that would separate the objects, something that in general is difficult. The separation distance between two disjoint object A and B is defined as the minimum of the distance between points in A and B. A generalization of this problem is to find the closest points of A and B, a point in A and a point in B given the separation distance between the objects. Note that the closest points are not necessarily unique. For dynamic objects, computing the next time of collision is known as the estimate time of arrival (ETA), which can be used to control the time step in a rigid-body simulation.

2.3.3.

Geometries

Collision detection between simple geometries such as i.e. spheres and planes is well-defined and fairly simple compared to collision detection between more advanced geometries. The theory in this master thesis will focus on collision detection between more advanced geometries such as NURBS and revolution surfaces. For details about collision detection considering simple geometries, read (Ericson 2005 chapter 3).

As stated in section 2.1.6, NURBS have the property of convex hulls. Many convexity-based methods of collision detection currently exist and some of them will be discussed in 2.3.4.

2.3.4.

Intersection detection

Directly testing the geometry of two objects for collision against each other is often very expensive. To minimize this cost, object bounding volumes (BVs) are usually tested for overlap before the geometry intersection test is performed. A bounding volume is a single simple volume encapsulating one or more objects of more complex nature (Ericson, 2005 chapter 4). Not all geometric objects serve as effective bounding volumes. Desirable properties include:

(21)

 Tight fitting

 Inexpensive to compute

 Easy to rotate and transform

One of the most common bounding volumes is the axis-aligned bounding box (AABB) (Ericson, 2005 chapter 4). It is a rectangular box categorized by having its faces oriented in such a way that its face normals are at all times parallel with the axis of the given coordinate system. The best feature of the AABB is its fast overlap check. AgX internally uses AABB, and it will also be used in this thesis.

Unless otherwise stated, following section references to Ericson, 2005 chapter 6

The introduction of bounding volumes results in significant performance improvements, however although the tests themselves have been simplified, the same number of pairwise tests are still being performed. By arranging the bounding volumes into a tree hierarchy called a bounding volume hierarchy (BVH), the time complexity can be reduced to logarithmic in the number of tests performed. The original set of bounding volumes forms the leaf nodes of the tree. The nodes are grouped as small sets and enclosed within larger bounding volumes. This is repeated until eventually resulting in a tree structure with a single bounding volume at the top of the tree.

With this hierarchy, children do not have to be examined if their parent volume is not intersected when performing collision testing.

The complexity of intersection detection for NURBS depends on what type of object the NURBS object is colliding with. Algorithms similar to the ones described in Martin et al., (2000) can be used for line intersection, plane intersection and sphere intersection detections. For NURBS-NURBS intersection, Guillermo & Creus Fábio (2008) as well as Shankar & Dinesh (1997) lifts a new technique which may be used.

2.4. Physics engine

2.4.1.

Basics

A physics engine is software designed to reproduce certain physical systems, for example rigid body systems with collision detection.

Collision detection in physics engines can be categorized as a priori and a posteriori. A priori detection happens before the collision occurs, by taking into account movement of the objects in the simulation and predicting if when and where a collision occurs. A posteriori detection happens after a collision has occurred. A posteriori algorithms are a lot less complex than a priori methods and most general purpose physics engines including AgX use a posteriori approaches.

2.4.2.

AgX

In AgX, a posteriori collision detection is performed in three stages, broad phase, middle phase and narrow phase. In the broad phase, collision detection compares the AABBs of each object in the scene to detect if any pair of objects has a possible intersection. The object pairs found are sent to a specific collider, specially designed to handle that particular pair of geometries. AgX utilizes the BVH method described in Section 2.3.4 by grouping together objects that are spatially close.

In the middle phase, a vector of overlapping NURBS patches is found.

The final step in the collider is the narrow phase, where actual contact points are determined between the objects. The contact points are defined as the location of the point of intersection, the direction of separation and the depth of the intersection. The contact points found are collected from all collisions in the simulation for each time step, and sent to a solver that calculates how to best move each object to resolve the collisions.

For efficiency, a number of distinct geometries has been identified and implemented in AgX. Each possible geometric pair has their own separate collider to handle each specific case.

(22)
(23)

3. Studies

3.1. OpenNurbs

The OpenNurbs toolkit is designed with the purpose of reading and writing OpenNurbs 3D model files (.3dm files). Before implementing collision detection algorithms for BREPs it was of interest to investigate which functions where available in the OpenNurbs toolkit, as well as what kind of geometries were possible to implement using the toolkit. Very little documentation of the toolkit exists, hence the process of determining what functions were available involved going through source-code and trying to implement different functions described in the source-code.

At a first glance of the header files, many useful functions such as intersection detection between two different surfaces, and closest-point-on-a-surface functions were discovered. However, after further investigation it was clear that many functions described in the heather files were actually not implemented in the cpp files. By creating a cube shaped BREP like the one described in Section 2.2.2, implementations of the available functions were conducted to investigate what each function did.

After thorough experimentation, the following functions were deemed useful for the master thesis work:

 BREP topology and geometry access, i.e. access to the data stored in a BREP such as number of faces/edges/trims/vertices and access to each subset of data.

 Reading and writing of .3dm file format.

 For each topology and geometry, given a parameter-value, evaluation of corresponding 3D point.

 For each topology and geometry, given a parameter-value, evaluation of corresponding 3D derivative. Many different surface-types and curve-types are represented in OpenNurbs.

3.2. SpaceClaim models

A long-term goal for Algoryx is to be able to import 3D objects from the CAD program SpaceClaim into AgX. For this work, since the investigation was restricted to 800 working-hours, some limitations in what kind of surface and curve types that were to be implemented in the BREP structure in AgX were needed. To determine what kind of surfaces and curves that were of great interest, a study of a set of pre-constructed SpaceClaim models were conducted. It was decided that the surfaces and curves which occurred most frequently in the set of models provided were to be implemented in the AgX BREP structure during the master thesis work. The study was carried out by creating a simple subprogram in AgX which read a .3dm model and printed out what kind of surfaces and curves were included.

(24)
(25)

4. Algorithms

4.1. Geometric specific algorithms

For each geometry, sphere, line, plane and BREP, an algorithm to find the contact-points needed to be developed. Each algorithm uses Newton-Raphson method to find contact-points at the greatest depth.

Algorithm 2 Find closest point between BREP and geometry

1. Define a function to be minimized.

1a: For a line contact, the function to be minimized is the distance between the line origin and the BREP.

1b: For a plane contact, the function to be minimized is the normal of the plane times the derivative of the BREP in U and V directions.

1c: For a sphere contact, the function to be minimized is the normal of the closest distance between a sphere and BREP times the derivative of the BREP in U and V directions.

2. Use Newton-Raphson to minimize the given function in step 1.

3. Check if the contact-point is inside or outside the trimming curves, using algorithm 4.

4. Repeat for all surfaces and surface-elements whose AABBs are intersected by the specified geometry.

4.2. General algorithms

4.2.1.

Finding horizontal and vertical tangents to a trimming curve

In order to be able to create any kind of BREP-shape, a way to use the trimming curves located in the parameter space of the surfaces of the BREP to “trim away” outlaying regions needed to be found. First, each trim-curve needs to be divided into sub-intervals between roots of derivative of the curve, to ensure that all contact-points will be found. This is because Newton-Raphson only guarantees local convergence and needs a starting point within some bounds to converge to the global one. Each curve has its own parameter space with the parameter s, mapping to the u and v coordinates of the surface parameter space to which the curve belong. To find the roots of the derivative of the curve, algorithm 3 was used.

Algorithm 3 Finding of horizontal and vertical tangents to a trimming curve

1. Starting at the middle of the parameter space, compute , , , , , . 2. Use the Newton-Raphson method (section 2.1.2) to find a root given by or

.

3. Remove the interval .

4. Repeat steps 1-3 until either the same number of roots as the order of the curve is found, or all intervals have been removed.

A trimming loop is always closed. A trim curve however, can be either open or closed. A trimming loop consisting of only one trimming curve is therefore by definition built by a closed curve. Figure 5 displays a closed curve. Figure 8 below display a closed trimming loop consisting of two trimming curves.

(26)

Figure 8, The UV space of a NURBS surface, showing a trimming loop consisting of two

connected open trimming curves.

4.2.2.

Test to determine if a contact-point should be trimmed away

If a point is outside the trimming curves, it should be ignored. To determine if a point p in the uv-parameter space of a surface is inside or outside the trimming curves, algorithm 4 was used.

Algorithm 4 Test to determine if a point should be trimmed away

1. For each interval of each trimming curve, starting at the middle of the interval , compute u , .

2. Use the Newton-Raphson method to find the root to the function .

3. For each root, check if the u-distance is positive or negative, i.e. if the point is to the left of to the right of the trimming curve.

4. If the number of positive intersections is even, the point is outside the trimming region and can be ignored; otherwise the point is inside and should be considered a contact point.

For an illustration of algorithm 4 see figure 9.

Figure 9, the UV space of a NURBS surface, showing a trim curve and three points.

Studying

figure 9 and algorithm 4, we notice that the horizontal line starting at A and C cross the

trimming curve twice. Hence they are outside and is therefore considered trimmed away and

(27)

ignored. In contrast, the horizontal line starting at B crosses the trimming curve once. It is

therefore a possible contact point.

4.2.3.

Searching contact-points over a curve

For each geometry, the search for a contact-point was done using Newton-Raphson method. If however a step in the Newton-Raphson method would take the search outside a trim-curve, the search is restricted to be inside the trim-curve.

Algorithm 5 Search over trimming curves

1. For each step in the Newton-Raphson method, check if the line between the new and the previous search-point in the u-v subspace of the surface crossed a trim-curve.

2. If a trim-curve was crossed, start a new search in the middle of the trim curves subspace s.

3. At each search point in the trim-curve, find its corresponding real-world coordinates and approximate its derivatives by finite difference formulas.

(28)
(29)

5. Experiments

5.1. Spherical ball joint experiment

To test the functionality of the BREP implementation, two experiments modeling a spherical ball joint were constructed. The purpose of the spherical ball joint experiment is to compare the motion of a sphere with respect to contact depth, while encased in a spherically shaped hole represented by a BREP or a trimesh.

In the first experiment, the set of spheres were connected to a hinge in the z-axis. The hinge was designed as an engine-hinge, allowing the possibility to set a rotational torque on the hinge. The engine can be either of infinite torque, or set to a specific torque-range. A desired rotational velocity of 2 rps is specified. To validate the functionality, comparisons with a replica of the model but with the enclosing part of the lock joint made from trimesh shape, an AgX shape-type that approximates complicated geometries with triangles, were made (see figure 10). In theory, a sphere in a spherical hole would in the case of non-gravity have zero contact points.

The idea with the experiment was to test the smoothness of the BREP-shape and trimesh shape enclosing the sphere. The radius of the spherical hole in the BREP and the trimesh shape were set to 2.5 mm. Three different radii were chosen for the sphere. One undersized radius (2.472mm), one radius with the same size as the hole radius (2.5 mm), and one oversized radius (2.51mm). In the case of the trimesh, three different tessellations were tested; One rough tessellation, one smooth tessellation and one very smooth tessellation (in SpaceClaim chosen with 180 , 1 , 0.1 separation respectively). Figures 11 and 12 shows the different spheres.

Two types of tests were performed in this experimental setup. In the first test, the engine hinge was set to have “infinite” torque. This basically means that the engine can apply any torque needed to maintain the desired velocity of the rotating sphere. In this test, the depth of the contact points and the torque needed to maintain the desired velocity was recorded.

In the second test, three torque limits was set to the engine. These limits were chosen to be close to the torque needed to maintain desired velocity, with one limit set just below and one limit set just above. In this test, the rotational velocity at each time step was recorded.

.

Figure 10, a spherical ball joint, made from cubic shape with spherical hole in the center and

a set of connected spheres, with a larger sphere inside the cubic shape. BREP to the right,

(30)

Figure 11, spherical hole using the roughest tessellation with new triangles every 180 degree.

Figure 12, spherical hole using the middle tessellation with new triangles every 1 degree. The

visual difference between the middle trimesh tessellation, the finest trimesh tessellation and

the BREP is indistinguishable.

5.2. Shift gate experiment

In the second experiment, a more practical real-life situation was designed. Constructed from the same spherical ball joint, channels in the enclosing shape were designed using Space Claim, in order to replicate a shift gate (see figure 13). This experiment was designed to show that BREPs can construct complicated geometries and maintain contact functionality, and to show the possibility to operate with smooth surfaces.

(31)

Figure 13, a spherical ball joint with channels, representing a gear box. The gear stick is

constructed by a set of connected spheres.

5.3. Functionality tests

In addition to previous tests, functionality tests were constructed. A set of geometries were constructed using Space Claim, where the functionality of the collision algorithms for Line-BREP, Plane-BREP and Sphere-BREP collisions were tested.

(32)
(33)

6. Results

6.1. Spherical ball joint experiment

For all experiments, the friction coefficient of the material was set to AgX standard of 0.5. The masses of each object were set to AgX standard of 1kg. Below follows a table showing the results of the experiment with a rotating spherical ball joint.

Table 1, displaying result of the rotating spherical ball joint experiment, desired velocity

is 2.5 rps.

Radius 2.472 mm Space update

(ms/time step) Torque (Nm) Depth (mm) File (kb) size 180 degree tessellation 0.15 210000 0.220 55 1 degree tessellation 60.00 10600 0.013 5090 0.1 degree tessellation 1650.00 4043 0.003 16000 BREP 70.00 0 0 58 Radius 2.5 mm 180 degree tessellation 0.20 210000 0.28000 55 1 degree tessellation 120.00 41000 0.04119 5090 0.1 degree tessellation 3700.00 22540 0.04100 16000 BREP 495.00 2875 0.00011 58 Radius 2.51 mm 180 degree tessellation 0.20 220000 0.3100 55 1 degree tessellation 120.00 46800 0.0511 5090 0.1 degree tessellation 3900.00 29100 0.0510 16000 BREP 627.00 6166 0.0005 58

When studying table 1 one can draw some interesting conclusions. Starting with the case of the ball radius set to 2.472mm. In this case the ball radius was small enough to not get any contact points with the BREP-shape what so ever. This resulted in a very fast space update time, and after reaching the desired velocity, no required torque of the motor to keep the sphere spinning. This is expected, due to no air friction and no internal friction. When looking at the different trimesh tessellations, one noticess as expected that the more triangles, the longer the space update time. As expected, the smoothness of the surface also increases which can be seen both at the depth of the contact points, and at the torque required to reach (and maintain) the desired velocity. When comparing to the BREP-shape, one notices that even the finest tessellation still gets contact points, and hence doesn’t reach the same smoothness as the BREP-shape. Furthermore, the finest tessellation also radically worsens the space update time, to more than factor of 10 compared to the BREP-shape case.

Below follows figures displaying plots showing velocity vs time graphs for the case with the ball radius set to 2.5mm. Only the finest tessellation trimesh is studied.

(34)

Figure 14, plot showing velocity vs time for spinning sphere in BREP-shape, sphere radius

2.5mm, desired velocity 2rps, max torque 2850 Nm. Sphere in BREP-shape reaches 0.8rps,

and sphere in trimesh-shape reaches 0rps.

Figure 15, plot showing velocity vs time for spinning sphere in BREP-shape, sphere radius

2.5mm, desired velocity 2rps, max torque 2950 Nm. Sphere in BREP-shape reaches 2rps, and

sphere in trimesh-shape reaches 0rps.

0 0.5 1 1.5 0 0.2 0.4 0.6 0.8 1 1.2 1.4 Time(s) V e lo c it y (r p s )

Spinning sphere in BREP, desired velocity 2 rps, maxforce 2850 Nm

Rotational velocity, sphere in BREP-shape Rotational velocity, sphere in Trimesh-shape

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time(s) V e lo c it y (r p s )

Spinning sphere in BREP, desired velocity 2 rps, maxforce 2950 Nm

Rotational velocity, sphere in BREP-shape Rotational velocity, sphere in Trimesh-shape

(35)

Figure 16, plot showing velocity vs time for spinning sphere in trimesh-shape, sphere radius

2.5mm, desired velocity 2rps, max torque 22500 Nm. Sphere in BREP-shape reaches 2rps

instantly, and sphere in trimesh-shape reaches 1.4rps.

Figure 17, plot showing velocity vs time for spinning sphere in trimesh-shape, sphere radius

2.5mm, desired velocity 2rps, max torque 23000 Nm. Sphere in BREP-shape reaches 2rps

instantly, and sphere in trimesh-shape reaches 2rps later.

6.2. Shift gate experiment

In the shift gate experiment, a simple gearbox was constructed (see fig 13). Inside the gearbox was a large sphere in a spherical hole. Connected to the larger sphere were a set of smaller spheres to simulate a gear stick. By dragging in the top sphere, similar to a hand on top of a gear stick, the stick could be directed into the channels representing gears. Looking on figure 26, one notices the collision points between the small spheres (stick) and the gearbox represented by an orange arrow. Testing for each gear was performed, and it was possible with fairly small force to move the stick into each gear. An automated version was also created, where a small

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time(s) V e lo c it y (r p s )

Spinning sphere in trimesh, desired velocity 2 rps, maxforce 22500 Nm

Rotational velocity, sphere in BREP-shape Rotational velocity, sphere in Trimesh-shape

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time(s) V e lo c it y (r p s )

Spinning sphere in trimesh, desired velocity 2 rps, maxforce 23000 Nm

Rotational velocity, sphere in BREP-shape Rotational velocity, sphere in Trimesh-shape

(36)

sphere were connected to the top sphere in the gear stick with a Distance Joint connecting them, representing a spring. The small sphere was assigned different velocities in a sequence throughout a simulation run to represent moving a hand from gear 1 through 5. Images 18 through 28 below displays the shift gate experiment. The visible small “holes” on the edges of the box (and on other figures displaying BREPs) are not actually holes; they are just a visualization error due to the chosen tessellation approach for BREPs.

Figure 18, a spherical ball joint with channels, representing a shift gate. The gear stick is

constructed by a set of connected spheres.

Figure 19, a spherical ball joint with channels, representing a shift gate. Displaying the small

automatically moving sphere that is dragging the gearstick around.

(37)

Figure 20, a spherical ball joint with channels, representing a shift gate. Gearstick tilted to

the left.

Figure 21, a spherical ball joint with channels, representing a shift gate. Showing contact

points in the sphere, and mesh.

(38)

Figure 22, a spherical ball joint with channels, representing a shift gate. Gearstick in gear 1.

Figure 23, a spherical ball joint with channels, representing a shift gate. Showing orange

contact point, and switching of gear.

(39)

Figure 24, a spherical ball joint with channels, representing a shift gate. Gearstick in gear 2.

Figure 25, a spherical ball joint with channels, representing a shift gate. Showing orange

contact point, and switching of gear.

(40)

Figure 26, a spherical ball joint with channels, representing a shift gate. Gearstick in gear 3.

(41)

Figure 28, a spherical ball joint with channels, representing a shift gate. Gearstick in gear 5.

6.3. Functionality tests

A set of geometries were constructed using Space Claim in order to test the functionality of the collision algorithms for Line-BREP, Plane-BREP and Sphere-BREP collisions. Figure 29 through 47 shows testing done on the different geometries.

(42)

Figure 30, cubic box with one corner cut away, with trimming algorithm implemented.

(43)

Figure 32, cubic box with one corner cut away, displaying contact with plane at the trimmed

region.

(44)

Figure 34, cubic box with one corner cut away, displaying contact with sphere at trimmed

region.

(45)

Figure 36, cylinder shape, with trimming algorithm implemented. Displaying contact with

plane.

Figure 37, cylinder shape, with trimming algorithm implemented. Displaying contact with

plane (tilted).

(46)

Figure 38, cylinder shape, displaying contact with sphere.

(47)

Figure 40, curved and trimmed shape, displaying contact with line.

(48)

Figure 42, curved and trimmed shape, displaying contact with plane.

(49)

Figure 44, curved and trimmed shape, displaying contact with sphere.

(50)

Figure 46, “Geneva Device” contact with sphere.

(51)

7. Discussion

Comparing the space update time for the coarser tessellation trimeshes and BREP-shape, the BREP-shape is worse. As for the case where the ball radius is set to 2.5mm, the same radius as the hole in the shapes, one notices that also the BREP-shape gets contact points. This is due to the fact that the contact points are defined to have a contact when at the exact intersection, as well as due to some small numerical deviations due to discretization. Furthermore, NURBS are an approximation of reality, and hence the hole in the BREP-shape is not a perfect mathematical sphere. When studying the depth however, one notices that it even compared to the finest tessellation is a factor of 100 smaller then the depth of the trimeshes. Furthermore the torque required to reach the desired velocity are a factor 10 smaller than even the finest tessellation. Again the space update time is compared to the finest tessellation case much better.

Finally the case where the ball radius is clearly larger than the hole radius, the same pattern can be noticed. Again, the depth and torque required to reach the desired velocity in the BREP-shape is considerably smaller then for the trimesh cases, even the case with the finest tessellation.

The conclusions drawn from the experiments are that the BREP-shape will describe reality far better than trimesh-shapes in cases with smooth surfaces. It will however affect the space update time, and make the simulation run slower. However, when trying to improve the tessellation of the trimesh to reach a result comparable to reality at the same level as the BREP case, the space update time and cpu performance become a lot worse than for the BREP, and even then, the result cannot be compared to the BREP shape. Hence the BREP shape is very much preferable over the trimesh shape both in terms of computational speed and as representation of reality.

When studying the graphs in figures 14, 15, 16 and 17, one notices that when a limit is set to the motor, if the limit is set too low, the motor is not strong enough to reach the desired velocity and the velocity will stabilize at a set value. If again the limit is too low, the motor might not even be strong enough to start rotation what so ever. If the motor is strong enough to start accelerating the sphere and even reach the desired velocity, it will accelerate the sphere to the desired velocity, where the motor will return to the torque required to keep the sphere at this velocity. This corresponds well to reality.

In summary, the results show that the BREP representation of complex geometries has the potential to exceed trimesh representation both in terms of computational performance and in accurately describing reality. However, before BREPs can be considered fully operational, much work remains to be done in terms of generalization for collision detection, and in terms of speed and performance.

(52)
(53)

8. Future work

The initial testing and comparisons with trimesh shapes yielded positive results. However there are several places where the BREP method can be improved. Below is a list of recommended improvements.

 Develop collision detection for all geometries including BREP-BREP collision detection.

 Improve the method of derivative root finding to be faster and generalized to any degree.

 In all Newton-Raphson methods, find a better starting guess by initially using brute-force method of checking 100 points at the domain and choose the best as a starting guess.

 Allow for any kind of surface or curve type represented in Open Nurbs.

 Further develop the searching algorithms to improve computational speed.

 Make comparisons in computational power between converting all surfaces and curves to NURBS surfaces and curves and performing collision detection, and keeping all surfaces/curves in their original state.

(54)
(55)

9. Acknowledgments

I would like to gratefully and sincerely thank my examiner Niclas Börlin for his guidance during my master thesis work. Without his advices and support I would never have been able to complete this thesis.

Furthermore, I would like to thank my supervisor Michael Brandl for his guidance, patience and most importantly, his friendship. It has been a privilege to have the support of Michael.

I would also like to thank everybody at Algoryx, for letting me into their family. It has been a great experience for me, and I will forever cherish the memories, especially the coffee-football breaks.

(56)
(57)

10. References

Algoryx (2013, September). AgX Multiphysics and 3D simulation. Algoryx Simulation AB. http://www.algoryx.se/.

Efremov, A. (2004). Efficient Ray Tracing of Trimmed NURBS Surfaces. Master Thesis. Ericson, C. (2005). Real-time collision detection.

Martin, W., Cohen, E., Fish, R., Shirley, P (2000). Practical ray tracing of trimmed NURBS surfaces. Valkering, E. (2010). Ray Tracing NURBS Surfaces using CUDA. Master Thesis.

Piegl, L., Tiller, W. (1997) The NURBS Book (2nd ed.)

Albert, O (2005). Interactive Ray Tracing of NURBS Surfaces by Using SIMD Instructions and the GPU in Parallel. Master Thesis.

Poutrain, K., Contensin, M. (2001). Dual B-Rep-CSG collision detection for general polyhedral. Guillermo, J., Creus Fábio, G. (2008). A robust algorithm to determine surface/surface intersection in both parametric spaces.collision detection for general polyhedral.

Shankar, K., Dinesh, M. (1997). An efficient surface intersection algorithm based on lower-dimensional formulation.

Stroud, I. (2011). Solid Modelling and CAD Systems.

References

Related documents

In this chapter, the implementation of this thesis is illustrated. Two main problems are solved in this chapter: new backward projections and the multiresolution col- lision

If the ego-vehicle is already in a ”currently cut-in braking” state, v r,x and d x will continue to be fed to the CIB, unless the external vehicle backs out of the lane change, in

Keywords: Simulation-based optimization, response surface methodology, radial basis func- tions, multi-objective optimization, Pareto optimal solutions, trigger edge,

Using Monte Carlo methods together with the Bootstrap critical values, we have studied the properties of two tests (Trace and L-max), derived by Johansen (1988)

From the 2D results, it was found that the 2D fitted and Actual point coordinate sources of profile 1265 and 1865 have the closest fit in terms of blade loading, Mach/Pressure

Presentationen avslutas även med en svart sida och för att komma tillbaka till startsidan så klickar du bara vart som helst på sidan.. Efter genomgången presentation är

Chapter 3 covers collision detection specifics, such as different ways to implement middle phase collision detection and an important theorem often used for collision detection

The study focuses on Lean definition in healthcare, implementation process, barriers, challenges, enablers and outcomes of implementing lean production methods in