18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 1 Class 7 - Line Drawings  The LineList data type r Recursive methods to construct line drawings.

Slides:



Advertisements
Similar presentations
Trigonometry Math is beautiful. Is it? Well, if its not nice, than its damn sure of a very B.I.G. *HELP*.
Advertisements

By bithun jith maths project.
Escape Sequences \n newline \t tab \b backspace \r carriage return
Polar Coordinates We Live on a Sphere.
(r, ).
Pre-Calculus Chapter 6 Additional Topics in Trigonometry.
Methods Java 5.1 A quick overview of methods
Lecture 7 2D Transformation. What is a transformation? Exactly what it says - an operation that transforms or changes a shape (line, shape, drawing etc.)
Reading and Drawing Sine and Cosine Graphs
Special Angles and their Trig Functions
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
Building Java Programs
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
6/4/13 Obj: SWBAT plot polar coordinates
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Return values.
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
13.2 – Angles and the Unit Circle
Polar Coordinate System You are already familiar with the Rectangular Coordinate System.
Quiz Find a positive and negative co-terminal angle with: co-terminal angle with: 2.Find a positive and negative co-terminal angle with: co-terminal.
1 Computer Graphics Week6 –Basic Transformations- Translation & Scaling.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
TEKS 8.6 (A,B) & 8.7 (A,D) This slide is meant to be a title page for the whole presentation and not an actual slide. 8.6 (A) Generate similar shapes using.
Drill Calculate:.
PARAMETRIC EQUATIONS AND POLAR COORDINATES 9. Usually, we use Cartesian coordinates, which are directed distances from two perpendicular axes. Here, we.
Seven measuring the world (geo/metry). Measuring space This course is fundamentally about spaces of various kinds Physical space Image space Auditory.
TEKS 8.6 (A,B) & 8.7 (A,D) This slide is meant to be a title page for the whole presentation and not an actual slide. 8.6 (A) Generate similar shapes using.
Trigonometric Functions: The Unit Circle Section 4.2.
Lesson 4-7 Triangles and Coordinate Proof
Definition of Trigonometric Functions With trigonometric ratios of acute angles in triangles, we are limited to angles between 0 and 90 degrees. We now.
13.2 Angles and Angle Measure
Circumference of a Circle Parts of a circle Calculate d from r Calculate r from d Introducing pi Using C =π d C from d …. 5 circles C given radius 5 questions.
Trigonometric Functions of Any Angle & Polar Coordinates
7.5 The Other Trigonometric Functions
1 Circular Functions Just a fancy name for Trigonometry –Thinking of triangles as central angles in a circle Have done trigonometry ever since grade 9.
– Angles and the Unit Circle
Area (geometry) the amount of space within a closed shape; the number of square units needed to cover a figure.
Chapter 2: Fundamentals I. After completing this Chapter, you will be able to do the following: Construct Geometric Figures Use Coordinate Systems Additional.
Assignment P : 2-8, even, 30, 31, 34, 42 Complete Unit Circle Challenge Problems.
Chapter 6: Iteration Part 2. Create triangle pattern [] [][] [][][] [][][][] Loop through rows for (int i = 1; i
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
13.2 – Define General Angles and Use Radian Measure.
4.2 Day 1 Trigonometric Functions on the Unit Circle Pg. 472 # 6-10 evens, evens, 46, 54, 56, 60 For each question (except the 0 o, 90 o, 180 o,
Unit Circle You will use the Unit Circle for nearly every computation for the rest of Trig. Make the most of today… Memorize the angles and Radians Memorize.
Scalar Quantities Scalar quantities are measurements that have only magnitude (size) but no direction. Examples of scalar quantities are; Distance Speed.
5.3 The Unit Circle. A circle with center at (0, 0) and radius 1 is called a unit circle. The equation of this circle would be So points on this circle.
2/5/00SEM107 © Kamin & Reddy Review -1 Class 19 - Review r This lecture contains a selection of slides from previous lectures, giving the “high points”
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Radian and Degree Measure. Radian Measure A radian is the measure of a central angle that intercepts an arc length equal to the radius of the circle Radians.
Trigonometric Functions of Any Angle & Polar Coordinates
17/3/00SEM107 © Kamin & Reddy Class 13 - Animation 1 Class 13 - Animation r Summary of loops m while-do m for m do-while r while loop examples r for loop.
22/2/00 SEM107 © Kamin & Reddy Class 8 - Hilbert’s curve - 1 Class 8 - Recursive Pictures r Recursively-defined curves r The Hilbert curve.
This lesson will extend your knowledge of kinematics to two dimensions. This lesson will extend your knowledge of kinematics to two dimensions. You will.
Surveying for non-surveyors National Reference points whose Coordinates are known are used to determine coordinate value of points ( or stations) on site.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
11/2/00SEM107 © Kamin & ReddyClass 6 - Lists - 1 Class 6 - Recursion on Lists r More recursive methods on lists.
Notes 10.7 – Polar Coordinates Rectangular Grid (Cartesian Coordinates) Polar Grid (Polar Coordinates) Origin Pole Positive X-axis Polar axis There is.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
8/2/00SEM107- © Kamin and ReddyClass 5 - Lists - 1 Class 5 - Lists r The list data type r Recursive methods on lists.
Jeopardy Terminology Quiz Geometry All points on a circle are the same distance from this point. (100)
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Dilations A dilation is a transformation that produces an image that is the same shape as the original, but is a different size. A dilation stretches or.
translations, rotations, and reflections
Class 2 – Recursion on Lists
COORDINATE PLANE The plane containing the "x" axis and "y" axis.
Introduction Think about resizing a window on your computer screen. You can stretch it vertically, horizontally, or at the corner so that it stretches.
Finding Lengths of Horizontal Lines on a Coordinate Plane
slides created by Alyssa Harding
Programming with inheritance Based on slides by Alyssa Harding
Presentation transcript:

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 1 Class 7 - Line Drawings  The LineList data type r Recursive methods to construct line drawings

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 2 Line drawings It is possible to draw quite intricate pictures using only lines.

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 3 Graphics in Java r Can draw various shapes on the screen (we will see how next week) r Like most computer graphics systems, the window is divided into numbered pixels. r Pixels are numbered like this: (0,0) y increases x increases

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 4 Lines We will provide a class called Line, with several operations:  Construct a line from (x0,y0) to (x1,y1) by: new Line(x0,y0,x1,y1) m Given a line L, find coordinates of the starting and ending points using instance methods x0(), y0(), x1(), y1().  Lines can be printed by System.out.println.

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 5 Line lists The class LL has the same operations as IL, but contains operations on lists of Line objects: m LL.nil  LineList LL.cons(Line ln, LineList L) - construct a list containing ln at front  Line hd () - return head of L  LineList tl () - return tail of L m boolean empty ()

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 6 Creating line drawings  We will “draw” figures made up of lines, in the sense that we will create LineList ’s containing all of the lines. r Next week we will see how to turn these lists of lines into actual drawings

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 7 Example: Drawing vertical lines Given these five arguments:  int leng  int x  int y  int incr  int n draw n vertical lines, separated by incr horizontal distance. Each line is of length leng, and the first line is from ( x, y ) to ( x, y+leng ).

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 8 Example: Drawing vertical lines (cont.) For example, the call vertLines(50,0,0,10,3) produces the output (0,0,0,50),(10,0,10,50),(20,0,20,50) representing the drawing (0,0)

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 9 Example: Drawing vertical lines (cont.) As with all our recursive methods, we ask the question, how can a recursive call with “smaller” arguments help calculate the current call? Answer: if we can draw the first (leftmost) line, perhaps we can draw the rest of the lines recursively...

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 10 Drawing vertical lines (cont.) static LineList vertLines (int leng, int x, int y, int incr, int count) { if (count == 0) return LL.nil; else return LL.cons( new Line(x, y, x, y+leng), vertLines(leng, x+incr, y, incr, count-1)); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 11 Drawing lines at an angle To draw a line of length m at an angle theta from the x-axis:  m y = m sin  x = m cos  (But remember, this is upside-down...)

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 12 Drawing “stars” Given n and r, draw n lines of length r, each starting at the origin and spaced evenly around it. E.g. star(6,50) :

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 13 Drawing “stars” (cont.) This is one of those cases where the method you want to define cannot be defined recursively directly. Instead, you need a helper function that has more arguments. Here, you can define LineList star1 (int order, int radius, double theta, double angleIncr)

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 14 Drawing “stars” (cont.) which draws order lines of length radius separated by angleIncr radians, with the first at angle theta from the x-axis. Given this, define star : static LineList star (int order, int radius) { return star1 (order, radius, 0.0, 2*Math.PI/order); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 15 Drawing “stars” (cont.) static LineList star1 (int order, int radius, double theta, double angleIncr) { if (order == 0) return LL.nil; else return LL.cons( new Line(0, 0, (int)Math.round(radius*Math.cos(theta)), (int)Math.round(radius*Math.sin(theta))), star1(order-1, radius, theta+angleIncr, angleIncr)); } (Detail: Math.cos and Math.sin take arguments in radians, instead of degrees.)

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 16 “Translating” shapes There is a problem with our drawing of stars: it produces lines with negative coordinates, which don’t exist in the Java window. Moving a shape is called translating it. In this case, we want to move the star down and to the right by radius points. A general translation method for LineList’s is easy to write recursively:

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 17 “Translating” shapes (cont.) static LineList translate (LineList L, int x, int y) { if (L.empty()) return L; else { Line ln = L.hd(); Line transLine = new Line(ln.x0()+x, ln.y0()+y, ln.x1()+x, ln.y1()+y); return LL.cons(transLine, translate(L.tl(), x, y)); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 18 “Translating” shapes (cont.) Add translation to the star method: static LineList star (int order, int radius) { LineList S = star1 (order, radius, 0.0, 2*Math.PI/order); return translate(S, radius, radius); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 19 Drawing polygons A polygon is like a star, except that the lines are drawn between the end-points of the lines, instead of being drawn from the center. We define polygon (int order, int radius) to draw a polygon with order sides and vertices a distance radius from the origin

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 20 Drawing polygons (cont.) static LineList polygon (int order, int radius) { return polygon1(order, radius, 0.0, 2*Math.PI/order); } Again, polygon cannot be computed directly, but can be computed using LineList polygon1 (int order, int radius, double theta, double angleincr) which draw order lines between points at distance radius from the origin, given also that the first line is at angle theta from the x-axis, and the lines are separated by angleincr radians.

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 21 Drawing polygons (cont.) static LineList polygon1 (int order, int radius, double theta, double angleincr) { if (order == 0) return LL.nil; else { int x0 = (int)(radius*Math.cos(theta)); int y0 = (int)(radius*Math.sin(theta)); int x1 = (int)(radius*Math.cos(theta+angleincr)); int y1 = (int)(radius*Math.sin(theta+angleincr)); return LL.cons(new Line(x0,y0,x1,y1), polygon1(order-1, radius, theta+angleincr, angleincr)); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 22 Drawing polygons (cont.) An unfortunate feature of polygon1 is that it calculates all four points on each recursive call, even though two of them have already been calculated on the previous call. Since sin and cos are fairly expensive, we can avoid this calculation by passing two of the points along to each call:

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 23 Drawing polygons (cont.) static LineList polygon1 (int order, int radius, double theta, double angleincr, int x0, int y0) { if (order == 0) return LL.nil; else { int x1 = (int)(radius*Math.cos(theta+angleincr)); int y1 = (int)(radius*Math.sin(theta+angleincr)); return LL.cons(new Line(x0,y0,x1,y1), polygon1(order-1, radius, theta+angleincr, angleincr, x1, y1)); }

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 24 Drawing polygons (cont.) Now, polygon must call polygon1 with two extra arguments: static LineList polygon (int order, int radius) { double theta = 2*Math.PI/order; int x0 = (int)(radius*Math.cos(theta)); int y0 = (int)(radius*Math.sin(theta)); return polygon1(order, radius, 0.0, theta, x0, y0); }