
Applying MATLAB to Computer Graphics and CAGD. Application to a Visualization Problem in the Automotive Industry. Akemi Gálvez1, Andrés Iglesias1,*, Flabio Gutiérrez2 1Department of Applied Mathematics and Computational Sciences, University of Cantabria Santander, Spain 2Department of Mathematics, National University of Piura, Piura, Peru * Corresponding author. used in this paper are also discussed in this section. Then, Abstract Section 3 introduces some additional commands we need to implement in order to solve some interesting problems Computer graphics are usually achieved by using some related to CAGD and computer graphics. This section also traditional programming languages (Fortran, Pascal, C, includes a wide description of the main MATLAB etc.). In this paper an extensive use of the general-purpose graphical commands, options and utilities that will be numerical computation programs (NCPs) in the computer useful for rendering surfaces. As an application, Section 4 graphics field is proposed instead of. The paper describes shows how they can be successfully applied to solve a the main advantages of this kind of programs, and several given visualization problem coming from the automotive examples of how they can be successfully applied to industry. Today, many industries are concerned about the computer graphics and visualization. Moreover, the paper possibility to transfer their information by Internet, briefly introduces several functions and commands avoiding other possible and slower transference ways. developed by the authors, which will be successfully Section 5 discusses such a possibility for the visual applied to solve a visualization problem coming from the information, through the MATLAB-VRML connection. automotive industry. Finally, the paper closes with the main conclusions and Keywords: Computer Graphics, MATLAB, CAGD. remarks of this work. 1. INTRODUCTION 2. ADVANTAGES OF THE NCP Computer graphics play a fundamental role in engineering In this section we show the main advantages of the NCPs, design, capturing the visual and quantitative aspects of the which justify our proposal to apply them to the computer geometric objects. For example, in the automotive industry, graphics field. Then, we proceed to choose the program to one is interested not only to obtain the curves and surfaces be used along the paper. holding some prescribed constrains but also to join all these geometric entities together and to visualize the resulting 2.1 Why to use NCPs for Computer picture in order to take care the aesthetic features and the Graphics? general look of the product. There are many reasons to explain why we propose the Many of the most important programs for computer NCPs to be used in the computer graphics field. Some of graphics have been written in traditional programming them are listed below: languages (Fortran, Pascal, C, etc.) However, in the last • The NCPs are easier to use, because: recent years, the general-purpose numerical computation − they incorporate many mathematical and programming programs (NCPs) are gaining more and more popularity. commands and libraries Today, they are well established as a powerful alternative to the traditional programming languages in many different − their algorithms are very optimized areas, as mechanical engineering, signal processing, quality − they have a powerful and user-friendly interface control, electronic circuits, etc. • The NCPs are very powerful, because: In this context, it would seem natural to wonder if the − their programming languages incorporate not only the NCPs could be applied, instead of the traditional procedural but also the functional programming programming languages, in the computer graphics field. including, in several cases, pattern recognition and The present paper tries to answer this question by object-oriented programming. following the next sequence: Section 2 describes the main advantages of this kind of programs. In addition, the main − they have a very remarkable graphical capabilities. reasons to justify our choice of MATLAB as the NCP to be International Conference Graphicon 1999, Moscow, Russia, http://www.graphicon.ru/ Based on these considerations, our research group enough to allow the programmer to improve the algorithms undertook the ambitious task to apply the NCPs to and codes in an efficient, quick and easy way. computer graphics. The following paragraphs are devoted MATLAB incorporates some useful commands for CAGD. to show how this work has been performed, indicating the For instance, its kernel includes a basic command for main advantages of our approach. interpolation through cubic splines and some other 2.2 Choosing the NCP: MATLAB commands for interpolation in one and several variables. However, the system lacks of many of the most important Evidently, not all the NCPs offer the same advantages and mathematical entities for CAGD, such as Bézier and B- features. Therefore, the first thing to be done in this line is spline curves and surfaces, which must be implemented. to choose the program to work with. After a careful The powerful MATLAB functional programming offers us analysis, our final choice was MATLAB (see the the possibility to implement these functions in a short, MathWorks Home Page at: http://www.mathworks.com). In elegant and simple code. As an illustration, the following this choice we took into account some features as: script calculates and displays the Bézier curve of a given • Spreading. MATLAB is used for hundreds of thousands set of two- or three-dimensional points: of industrial, government and academic users around the world. Its last versions are available for Microsoft function Bezier(ptos) % main function Windows 9x and NT, Macintosh and Linux personal [n,d]=size(ptos); Computers, as well as UNIX workstations from Sun, n=n-1; bt=ptos'*mij(n)*ti(n); Hewlett-Packard, IBM, Silicon Graphics and Digital, if d==2 and Open VMS computers. plot(bt(1,:),bt(2,:),ptos(:,1),ptos(:,2),'r-.p') • Graphical capabilities, which raise many of the current else plot3(bt(1,:),bt(2,:),bt(3,:), ... graphics-oriented programs (see Section 3.2). ptos(:,1),ptos(:,2),ptos(:,3),'r-.p') • Since MATLAB is based on C, it runs faster than other end rotate3d analyzed symbolic and numerical programs. Moreover, its basic element is an array that does not require function T=ti(n) % generating the t^i dimensioning, so it takes less time to be computed. m=1; It must be noticed that, in spite of our choice, the same t=0:0.05:m; % step=0.05 results can be obtained by using some other NCPs. For T=[]; for i=0:n example, SCILAB (see [1] for details) is a free software T= [T;t.^i]; whose programming and graphical capabilities are very end similar (although slightly lower for our purposes) to those of MATLAB. However, we think this last one is more function M = mij(n) popular and used in academic and industrial environments. for i=0:n for j=0:n M(i+1,j+1)=(-1)^(ji)*binom(n,j)*binom(j,i); 3. APPLYING MATLAB TO CAGD AND end COMPUTER GRAPHICS end M=M(1:n+1,1:n+1); The aim of this section is twofold: on the one hand, Section function c=binom(n,i) % defining the binom function 3.1 introduces some additional commands we need to solve if i==n | i==0 a visualization problem described in Section 4 and other c=1; interesting problems related to CAGD and computer elseif i<n & i>=0 graphics. On the other hand, Section 3.2 describes the main c=factorial(n)/(factorial(i)*factorial(n-i)); MATLAB commands, options and utilities that will be else useful for rendering surfaces. c=0; end 3.1 Building numerical libraries for CAGD function f=factorial(n) %defining the factorial function Once the program is chosen, the following task to be done if n==1 is the implementation of an extensive set of numerical f=1; libraries for CAGD. By "extensive" we mean the libraries else must contain all the relevant geometric entities in the sense f=n*factorial(n-1); end that if a given geometric entity is useful in CAGD, it must be incorporated to the system. Of course, libraries must be continuously updated, so the system must be flexible Table 1: MATLAB code for the Bézier curves. International Conference Graphicon 1999, Moscow, Russia, http://www.graphicon.ru/ We remark that this example has been chosen primarily for • Two- and three-dimensional transformations. Since simplicity, rather than to correspond to a valuable code or a all these transformations are not available directly in very complicated algorithm. However, some questions MATLAB, they were implemented in the toolbox. deserve to be pointed out: as the reader may appreciate, we use the matrix form for the Bézier curves (see, for example, • Projections and perspectives. MATLAB only [2] pag. 58). This is not a chance: MATLAB handles supports some kinds of projections and perspectives. vectors and matrices in a straightforward and intuitive way. The toolbox incorporates all of them. Furthermore, there are typically many different ways to 3.2 MATLAB graphics commands formulate a given problem in MATLAB; in almost all cases, however, the best performance is expected when MATLAB provides a set of powerful high-level graphical matrix formulation is applied. The simple idea of routines for displaying both two- and three-dimensional organizing data in a matrix form yields to programs that are graphics. However, since we are mainly concerned about more efficient and easier to understand. Thus, Table 2 the three-dimensional pictures, the following description is shows the corresponding code for Bézier surfaces (which restricted to this case (which includes the 2-D case for can be easily derived from Table 1): many commands). In the following we describe the most important MATLAB features for computer graphics (the corresponding commands are denoted in courier font style). function SupBezier(ptos) [m,n,o]=size(ptos); for k=1:3 (1).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-