Mathematics for Computer Graphics - Lecture 8

Similar documents
Mathematics for Computer Graphics - Ray Tracing III

Mathematics for Computer Graphics - Lecture 13

Mathematics for Computer Graphics - Lecture 12

Introduction to JAVA Programming Language

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Object Oriented Concepts and Programming (CSC244) By Dr. Tabbasum Naz

Welcome to CS 4/57101 Computer Graphics

NEW YORK CITY COLLEGE OF TECHNOLOGY/CUNY Computer Systems Technology Department

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Introduction to Java Programming

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Mcq In Computer Graphics

Computer Graphics. Instructor: Oren Kapah. Office Hours: T.B.A.

Merge Sort Quicksort 9 Abstract Windowing Toolkit & Swing Abstract Windowing Toolkit (AWT) vs. Swing AWT GUI Components Layout Managers Swing GUI

Chapter 1 Introduction to Computers, Programs, and Java

History Introduction to Java Characteristics of Java Data types

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Introduction Welcome! Before you start Course Assessments The course at a glance How to pass M257

Computer Graphics Introduction. Taku Komura

2 Introduction to Java. Introduction to Programming 1 1

Computer Graphics II: Tools and Techniques

Introduction to Java

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

More About Objects and Methods

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

JAVA: A Primer. By: Amrita Rajagopal

Implementing Object Equivalence in Java Using the Template Method Design Pattern

CSC 425 Computer Graphics and Games

SRI VENKATESWARA COLLEGE OF ENGINEERING. COURSE DELIVERY PLAN - THEORY Page 1 of 6

Java Programming Manual Windows

B. Subject-specific skills B1. Problem solving skills: Supply the student with the ability to solve different problems related to the topics

ENCE 688R Civil Information Systems

College Board. AP CS A Labs Magpie, Elevens, and Picture Lab. New York: College Entrance Examination Board, 2013.

Java Camp Daily Schedule

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

Getting Started with Java. Atul Prakash

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

DATA STRUCTURES CHAPTER 1

COURSE DELIVERY PLAN - THEORY Page 1 of 6

Pace University. Fundamental Concepts of CS121 1

Computer graphics 2. Róbert Bohdal, FMFI UK M-114, flurry.dg.fmph.uniba.sk/webog/bohdal

Sun ONE Integrated Development Environment

The University of Aizu School of Computer Science and Engineering Introduction to Programming. Course Syllabus (Special Track for Foreign Students)

1 Preview. Dr. Scott Gordon Computer Science Dept. CSUS. Virtual Cameras, Viewing Transformations: CSc-155 Advanced Computer Graphics

Lesson 6 Introduction to Object-Oriented Programming

G51OOP. Object Oriented Programming Comp Sci University of Nottingham Unit 1 : Introduction

CE221 Programming in C++ Part 1 Introduction

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Introduction to Computers and Java

Lecture 1 - Introduction (Class Notes)

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B

Introduction to Java and OOP. Hendrik Speleers

CS Systems Qualifying Exam 2017

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

CS112 Lecture: Working with Numbers

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Bitwise Operators Objects and Methods

Defining Classes and Methods

Java3018: Darkening, Brightening, and Tinting the Colors in a Picture *

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Compilers Project Proposals

CS Systems Qualifying Exam 2016

Introduction to Computers and Java

Fundamentals of Programming. By Budditha Hettige

Programming In Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

Syllabus CS476 COMPUTER GRAPHICS Fall 2009

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

CS Systems Qualifying Exam 2014

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

Advanced Object-Oriented Programming Introduction to OOP and Java

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

Computer Programming, I. Laboratory Manual. Final Exam Solution

Object Oriented Program Correctness with OOSimL

Course Outline. Introduction to java

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Chapter Goals. Contents INTRODUCTION

Course Title: Computer Graphics Course no: CSC209

Java Software Solutions For Ap Computer Science A 2nd Edition

Java Concepts: Compatible With Java 5, 6 And 7 By Cay S. Horstmann

Object-Oriented Programming in Java

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

JAVA An overview for C++ programmers

Chapter 1 Introduction to Computers, Programs, and Java

CSM #1: Calculus II & III Short Course

Selected Java Topics

function [s p] = sumprod (f, g)

Transcription:

Mathematics for Computer Graphics - Lecture 8 Dr. Philippe B. Laval Kennesaw State University September 22, 2003 Abstract This document is about our rst project: the creation of a 3D vector class. It gives the speci cations for this class. It also gives some programming techniques students should follow. 1 Developing a 3D Vector Class Recall that one of our goals in this class is to develop a small software package which will illustrate some of the techniques involved with 3D graphics. We will build this package in stages. The smallest building block of this package is 3D vectors. We begin by implementing them. 1.1 Goal The goal of this rst project is to develop a 3D vector class. We will also develop a test program to test our class. Though the nal software package will be implemented as an applet, this rst project can be implemented as a java application. See below for the di erence between the two. 1.2 Programming Techniques to Follow 1.2.1 Java Applets versus Java Applications Usually, when a program written in most programming languages such as C, C++, pascal, Fortran,... is compiled, an executable is produced. The executable code is written in machine dependent code a particular machine can understand. To run the program, one then either types its name, or double clicks on it. Java is an interpreted language. When a java program is compiled, a class le is produced. A class le is written in machine independent code. A class le cannot be run by itself. It can only be run inside the java runtime environment. Each machine type has its own version of the java runtime environment. They all can run the same class le. A java class le can be run in one of two ways. The method used will be determined by whether we have a java applet or a java application. 1

A java applet runs inside a web browser. When a java applet is developed, one must also write an html le which will call the applet. Many java IDE s do this for you. For this to work, the web browser must implement the Java Virtual machine. This is the case for many browsers including Netscape. For Internet Explorer, the situation is more delicate. Microsoft is no longer shipping the Java Virtual Machine (Java VM). It can be downloaded from http://java.sun.com. In contrast, a java application runs alone, like any other program. Well, almost like any other program. Since it has to be run inside the java runtime environment, the java runtime environment is invoked, with the class le to run as a parameter. For example, to run a class le named myprogram.class, one would type java myprogram. There are also other di erences between java applets and applications. Here are a few outlined here. An important one deals with security. Since a java applet will be more than likely run across the internet, its access to the local le system is highly restricted. A java application must have a method called main, a java applet does not. 1.2.2 Good Programming Techniques Here is a list of programming tips each student should follow: A Java application or applet is usually made of several classes and a main class (the main class must have the same name as the program you are creating. If you create a program called test1, the main class will be called test1). The various classes implement the functionality of the program. The main class controls its ow. Use a di erent le for each class. At the beginning of every le, put comments explaining what the class does, how it does it. When declaring a variable, put comments indicating what this variable will be used for. When de ning a method, put comments indicating what the methods will do, what its parameters are, what the method will return. Insert plenty of comments in your code explaining what you are doing, how you are doing it. 1.3 Tools to Use If you are going to work from the computers on campus, you do not have any choice. You must use what is installed on them. JGrasp is the IDE installed on them. If you are going to work from your own computer, you rst must have the following: 2

1. Java Software Development Kit (JSDK). This can be downloaded from Sun Microsystems at java.sun.com. The current latest version (J2SE 1.4.2 SDK). This contains all the runtime libraries needed as well as an IDE called NetBeans. This IDE has a lot of functionality, including a GUI builder. 2. A java IDE. You can either get a commercial one. There are also free ones. Here are some IDE s listed below. JBuilder. It is a commercial package, not very expensive for students. It has a lot of functionality, including a GUI builder. The web site for this software is: http://borland.com/jbuilder/index.html. JCreator. There is a free version available. It is simple to use. The web site for this software is: http://www.jcreator.com/ Eclipse. This is also a free IDE. It is a little bit more complex to use, but it has more functionality than JCreator. The web site for this software is: http://eclipse.org/. 3. The Java VM to run the applets. To see if you have it, try to run some of my applets at http://science.kennesaw.edu/~plaval/tools/index.html. If you see a red X where the applet should be, it means you need to install the java VM. You can download it from Sun Microsystems at java.sun.com. I have made a CD containing the J2SE 1.4.2 SDK as well as the free IDE s mentioned above. If you need one, ask me. Even if you use my CD (to save download time), you should visit the web site of the product you select, for installation instructions and other information. If you do not have a favorite java IDE, I suggest you use NetBeans. It is free, has a GUI builder and all the functionality we will need in this class. 1.4 Class Speci cations As we build this class, we have to answer the following questions: 1. What is the data this class will operate on? This includes what data type. Do we need a separate class for points and vectors? 2. Should the data be public, private? 3. What constructors do we want for the class? 4. What are the operations we want to perform on the data? 1.4.1 Data This class is designed to handle 3D vectors. A 3D vector has 3 coordinates, x, y, and z. There are two questions to answer here. 3

1. Since we know that we will be using homogeneous coordinates, should we assign 4 coordinates to the vector? Since the fourth coordinate is 1, we do not need to store it. 2. What data type should each coordinate have? We do not need the precision doubles would give us. We will use oat for the data type of x, y and z. 3. Do we need a separate class for points. Since points are also represented with three coordinates, we do not. It is not necessary to add a separate class for points. As far as our software is concerned, we will treat points as vectors. We can always add such a class if it becomes necessary. 4. The name of the class will be vect3d. 1.4.2 Public versus private data Usually, all data within a class is private. The internals of a class should be hidden from the user. In this case, the class is simple. It represents a vector, so we know what the data is. The x, y and z coordinates of the vector. 1.4.3 Class Constructors There should be a default constructor, called with no arguments. It creates an object of this class, and sets its coordinates to 0. Since a vector can be constructed from either a point (it is the vector from the origin to that point) or from two points, we need a constructor for each situation. 1.4.4 Operations We need the basic operations on vectors. For each operation, we need to decide how to call it, what its arguments are, how it will be used, what it will return. Addition Name: add Parameters: 1 parameter of type vect3d, the second vector to add. What it does: adds 2 vectors. Subtraction Name:minus Parameters: 1 parameter of type vect3d, the second vector to subtract. 4

What it does: subtracts 2 vectors. Multiplication by a scalar Name: times Parameters: 1 parameter of type oat, the scalar by which we multiply. What it does: multiplies a vector by a scalar. Dot product Name:dot Parameters: 1 parameter of type vect3d, the second vector to take the dot product with. Return type: an object of type oat. What it does: takes the dot product of two vectors. Cross product Name: cross Parameters: 1 parameter of type vect3d, the second vector to take the cross product with. What it does: takes the cross product of two vectors. We could also use functions to check the following: If a vector is the zero vector Name: iszero Parameters: none Return type: boolean (true or false) What it does: checks to see if the vector is the zero vector. If two vectors are equal Name: isequal Return type: boolean What it does: checks to see if the two vectors are equal. 5

If two vectors are parallel Name: isparallel Return type: boolean What it does: checks to see if the two vectors are parallel. If two vectors are perpendicular Name: isperp Return type: boolean What it does: checks to see if the two vectors are perpendicular. We could have additional functions for the following: Find the norm of a vector Name: norm Parameters: none Return type: an object of type oat What it does: returns the norm of a vector Normalize a vector Name: normalize Parameters: none What it does: returns a vector having the same direction, of length 1. Finds the distance between two points Name: dist Return type: an object of type oat What it does: compute the distance between the two points (which are treated as vectors) 1.4.5 Conclusion We will develop a class named vect3d, whose data is the x, y and z coordinates of a vector, of type oat. This class will have the methods described above. 6

2 Assignments 1. Implement the 3D vector class as described in this document. You will also write a test program which can be used to test your code. The test program should test all the methods in your class. The test program will be called test1. The program is due on Monday September 29. 2. The next project is to develop a matrix class so we can implement the various transformations. Think about the speci cations such a class should have. We will discuss these at our next meeting, and make the speci cations of the class nal. 3 Resources This is a list of books and other resources I used to compile these notes. References [BG1] Burger, Peter, and Gillies, Duncan, Interactive Computer Graphics, Addison-Wesley, 1990. [DP1] Dunn, Fletcher and Parberry, Ian, 3D Math Primer for Graphics and Game Development, Wordware Publishing, Inc., 2002. [FD1] Foley, J.D., Van Dam, A., Feiner, S.K., and Hughes, J.F., Computer Graphics, Principles and Practices, Addison-Wesley, 1995. [FD2] Foley, J.D., Van Dam, A., Feiner, S.K., Hughes, J.F., and Philipps, R.L., Introduction to Computer Graphics, Addison-Wesley, 1997. [H1] Hill, F.S. JR., Computer Graphics Using Open GL, Prentice Hall, 2001. [LE1] Lengyel, Eric, Mathematics for 3D Game Programming & Computer Graphics, Charles River Media, Inc., 2002. [SE1] Schneider, Philip J., and Eberly, David H., Geometric Tools for Computer Graphics, Morgan Kaufman, 2003. [SP1] Shirley, Peter, Fundamentals of Computer Graphics, A K Peters, 2002. [SJ1] Stewart, James, Calculus, Concepts and Contexts, second edition, Brooks/Cole, 2001. [AW1] Watt, Alan, 3D Computer Graphics, Addison-Wesley, 2000. [AW2] Watt, Alan, The Computer Image, Addison-Wesley, 1999. 7