Topic 2b Building Geometries into Data Arrays

Similar documents
Building Geometries in Data Arrays

Module 2 Spatially-Variant Planar Gratings

Revision Topic 11: Straight Line Graphs

Topic 0b Graphics for Science & Engineering

Introduction to Homogeneous coordinates

Direction Fields; Euler s Method

Chapter 4 Determining Cell Size

Transformations. Write three rules based on what you figured out above: To reflect across the y-axis. (x,y) To reflect across y=x.

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Part 3: 2D Transformation

Worksheet 3.1: Introduction to Double Integrals

I IS II. = 2y"\ V= n{ay 2 l 3 -\y 2 )dy. Jo n [fy 5 ' 3 1

Lecture 12: Grids Steven Skiena. skiena

Centroid Principles. Object s center of gravity or center of mass. Graphically labeled as

Unit #13 : Integration to Find Areas and Volumes, Volumes of Revolution

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Chapter 12 Transformations: Shapes in Motion

Proceedings of the Third International DERIVE/TI-92 Conference

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

YEAR 8 SCHEME OF WORK

AQA GCSE Further Maths Topic Areas

Topic 8a Introduction to Optimization

The SciPy Stack. Jay Summet

N-Views (1) Homographies and Projection

(Section 6.2: Volumes of Solids of Revolution: Disk / Washer Methods)

YEAR 9 MATHS. Monday Wednesday Thursday - - Friday Introduce: 10A Distance between two points 10A.1. WEEK 3 Coordinate Geometry.

Introduction to Matlab

Graphics and Interaction Transformation geometry and homogeneous coordinates

Announcements. Edges. Last Lecture. Gradients: Numerical Derivatives f(x) Edge Detection, Lines. Intro Computer Vision. CSE 152 Lecture 10

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Chapter 2: Transformations. Chapter 2 Transformations Page 1

Chapter 8 Complex Numbers & 3-D Plots

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

6.1 The Rectangular Coordinate System

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

VOLUME OF A REGION CALCULATOR EBOOK

Lofting 3D Shapes. Abstract

Microsoft Office Word 2013 Intermediate. Course 01 Working with Tables and Charts

Edge Detection (with a sidelight introduction to linear, associative operators). Images

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Rational Numbers: Graphing: The Coordinate Plane

Computer Graphics. - Rasterization - Philipp Slusallek

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

Double integrals over a General (Bounded) Region

Agenda. Rotations. Camera calibration. Homography. Ransac

E0005E - Industrial Image Analysis

From Ver(ces to Fragments: Rasteriza(on

Chapter 8: Implementation- Clipping and Rasterization

We imagine the egg being the three dimensional solid defined by rotating this ellipse around the x-axis:

Contents. MATH 32B-2 (18W) (L) G. Liu / (TA) A. Zhou Calculus of Several Variables. 1 Homework 1 - Solutions 3. 2 Homework 2 - Solutions 13

Topic 3. Mathematical Operations Matrix & Linear Algebra Operations Element-by-Element(array) Operations

if nargin < 2, niter = 80; end if nargin < 3, beta = 2^4; end % defaults appropriate for HW problem if nargin < 4, delta = 0.

Teaching Manual Math 2131

1 Affine and Projective Coordinate Notation

Multimedia Computing: Algorithms, Systems, and Applications: Edge Detection

18.02 Multivariable Calculus Fall 2007

2D Object Definition (1/3)

Agenda. Rotations. Camera models. Camera calibration. Homographies

Mechanical Engineering Department Second Year (2015)

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss

Teaching Math thru Big Ideas Focusing on Differentiation. Marian Small April 2017 San Diego, CA

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Quickstart for Web and Tablet App

Department Curriculum Map (new GCSE)

Edge Detection. CSE 576 Ali Farhadi. Many slides from Steve Seitz and Larry Zitnick

HOUGH TRANSFORM. Plan for today. Introduction to HT. An image with linear structures. INF 4300 Digital Image Analysis

AP Calculus. Slide 1 / 95. Slide 2 / 95. Slide 3 / 95. Applications of Definite Integrals

Lecture 17. ENGR-1100 Introduction to Engineering Analysis CENTROID OF COMPOSITE AREAS

Integrated Algebra A Packet 1

QUIZ 4 (CHAPTER 17) SOLUTIONS MATH 252 FALL 2008 KUNIYUKI SCORED OUT OF 125 POINTS MULTIPLIED BY % POSSIBLE

MEI Casio Tasks for A2 Core

8 Piecewise Polynomial Interpolation

MEI GeoGebra Tasks for A2 Core

CS 130. Scan Conversion. Raster Graphics

We start by looking at a double cone. Think of this as two pointy ice cream cones that are connected at the small tips:

Unit 3 Transformations and Clipping

CS 325 Computer Graphics

Laboratory 1 Introduction to MATLAB for Signals and Systems

FOUNDATION HIGHER. F Autumn 1, Yr 9 Autumn 2, Yr 9 Spring 1, Yr 9 Spring 2, Yr 9 Summer 1, Yr 9 Summer 2, Yr 9

Summer 2009 REU: Introduction to Matlab

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

Year Nine Scheme of Work. Overview

lecture 16 Texture mapping Aliasing (and anti-aliasing)

Loki s Practice Sets for PUBP555: Math Camp Spring 2014

Middle School Math Course 3

"Unpacking the Standards" 4th Grade Student Friendly "I Can" Statements I Can Statements I can explain why, when and how I got my answer.

Homework #5. Plot labeled contour lines of the stresses below and report on how you checked your plot (see page 2):

The Straight Line. m is undefined. Use. Show that mab

Collisions/Reflection

Spreadsheet Warm Up for SSAC Geology of National Parks Modules, 2: Elementary Spreadsheet Manipulations and Graphing Tasks

5 Applications of Definite Integrals

NAME: PD DATE / / 2. The Name of this Tool is: A: The Text Tool B: The Type on a Path Tool C: The Selection Tool D: The Gradient Mesh Tool

FDP on Electronic Design Tools - Computing with MATLAB 13/12/2017. A hands-on training session on. Computing with MATLAB

Introduction to MATLAB

Lecture 7: Most Common Edge Detectors

6 Mathematics Curriculum

Math 6, Unit 8 Notes: Geometric Relationships

GeoGebra. 10 Lessons. maths.com. Gerrit Stols. For more info and downloads go to:

Transcription:

Course Instructor Dr. Raymond C. Rumpf Office: A 337 Phone: (915) 747 6958 E Mail: rcrumpf@utep.edu Topic 2b Building Geometries into Data Arrays EE 4386/5301 Computational Methods in EE Outline Visualizing MATLAB Data and Arrays 3D 2D 1D Arrays, x and y in MATLAB Building Geometries in Arrays Initializing arrays Array indexing Squares and rectangles Simple triangles and arbitrary polygons Circles and ellipses Formed half spaces Linear half spaces Boolean operations Scaling data in arrays Lecture 2b Slide 2 1

WARNING: Not Meant for Graphics! This lecture teaches techniques that are NOT intended for generating graphics. See previous lecture if that is your purpose. Instead, the techniques in this lecture are intended for you to build arrays containing different shapes and geometries so that you can do numerical computation on those shapes and geometries. Beautiful Triangle Using fill() Ugly Triangle Using an Array Lecture 2b Slide 3 Visualizing MATLAB Data and Arrays Lecture 2b 4 2

1D Data Arrays Row Vectors >> a = [1, 2, 3, 4, 5] a = Row vectors are most commonly used to store onedimensional data. They can be used to label axes on grids, store functions, and more. Row vectors are used in some matrix algorithms, but less frequently. 1 2 3 4 5 x = linspace(-1,1,100); y = x.^2; Column Vectors >> a = [1 ; 2 ; 3 ; 4 ; 5] a = 1 2 3 4 5 Column vectors can be used the same way as row vectors, but column vectors are used more commonly in linear algebra and matrix manipulation. 0.8 0.6 1.0 1.00.4 2.66 0.9 0.1 1.0 0.5 0.9 1.75 0.1 0.3 0.2 0.80.8 1.27 0.9 0.5 1.0 0.11.0 1.71 Column vectors Lecture 2b Slide 5 2D Data Arrays >> A = [ 1 2 3 ; 4 5 6 ; 7 8 9 ] A = 1 2 3 4 5 6 7 8 9 A 2D array could be a matrix, a JPEG image, a 2D set of data, or many other things. MATLAB does not differentiate between these and treats them the same. It is up to you to know the difference and stay consistent in your code. >> imagesc(a); colorbar Lecture 2b Slide 6 3

Visualizing 1D Arrays >> phi = linspace(0,2*pi,10); >> y = sin(phi); >> plot(phi,y); >> phi = linspace(0,2*pi,10); >> y = sin(phi); >> stem(phi,y); Lecture 2b Slide 7 Visualizing 2D Arrays A = [1 2 3 ; 4 5 6 ; 7 8 9 ]; imagesc(a); colorbar; A = [1 2 3 ; 4 5 6 ; 7 8 9 ]; pcolor(a); colorbar; Lecture 2b Slide 8 4

linspace() vs. [a::b] LINSPACE xa = linspace(0,10,10); xa = 0 1.11 2.22 3.33 4.44 5.55 6.66 7.77 8.88 10.00 Easier to control number of points Easier to control position of end points. More difficult to control step size. DIRECT ARRAY Nx = 10; dx = 1; xa = [0:Nx-1]*dx; xa = 0 1 2 3 4 5 6 7 8 9 Easier to control step size. More difficult to control number of points. More difficult to control position of last point. Lecture 2b Slide 9 3D 2D 1D Lecture 2b 10 5

3D All physical devices are three dimensional. Lecture 2b Slide 11 Numerical Complexity Typical grid required to model a 3D device. Size of 3D Problem 20 20 100 = 40,000 points N 20 x N 20 y N 100 z Size of 2D Problem 20 100 = 2,000 points Size of 1D Problem 100 points Can we simulate 3D devices in one or two dimensions? Lecture 2b Slide 12 6

3D 2D (Exact) Sometimes it is possible to describe a physical device using just two dimensions. Doing so dramatically reduces the numerical complexity of the problem and is ALWAYS GOOD PRACTICE. z x y Lecture 2b Slide 13 3D 2D (Approximate) Many times it is possible to approximate a 3D device in two dimensions. It is very good practice to at least perform the initial simulations in 2D and only moving to 3D to verify the final design. n 1,eff n 2,eff Effective indices are best computed by modeling the vertical cross section as a slab waveguide. A simple average index can also produce good results. n 1,eff n 2,eff Lecture 2b Slide 14 7

3D 1D (Exact) Sometimes it is possible to describe a physical device using just one dimension. Doing so dramatically reduces the numerical complexity of the problem and is ALWAYS GOOD PRACTICE. Lecture 2b Slide 15 Arrays, x and y in MATLAB Lecture 2b 16 8

How MATLAB Indexes Arrays MATLAB uses matrix notation for indexing arrays. a11 a12 a13 a14 a21 a22 a23 a m is the row number 24 amn a31 a32 a33 a n is the column number 34 a41 a42 a43 a44 In MATLAB notation, a mn is indexed as A(m,n). In this sense, the first number is the vertical position and the second number is the horizontal position. This is like f(y,x) and so it is awkward for us to think about when the array is not a matrix. To be consistent with matrix notation, the index of the first element in an array is 1, not zero like in other programming languages like C or Fortran. Lecture 2b Slide 17 A More Intuitive Way of Indexing Arrays Experience suggests that one of the most challenging tasks in numerical modeling is representing devices on a grid. To be more intuitive, we would like the first argument when indexing an array to be the horizontal position and the second to be the vertical position so that it looks like f(x,y) instead of f(y,x). For this reason, we will treat the first argument of an array as the horizontal position and the second as the vertical position. This is consistent with the standard f(x,y) notation. Think A(nx,ny) instead of A(m,n). This is fine, but MATLAB still treats the array otherwise. We only need to consider how MATLAB handles things when using the meshgrid() command or when using plotting commands. Lecture 2b Slide 18 9

meshgrid() The meshgrid() command allows complex equations involving grid coordinates to be typed directly X into MATLAB without the need of using for loops to iterate across the grid. % GENERATE MESHGRID xa = [1:5]; ya = [3:9]; [Y,X] = meshgrid(ya,xa); ya Y xa Lecture 2b Slide 19 Revised Use of meshgrid() MATLAB Standard Use of meshgrid() xa = [0:Nx-1]*dx; ya = [0:Ny-1]*dy; [X,Y] = meshgrid(xa,ya); Revised Use of meshgrid() xa = [0:Nx-1]*dx; ya = [0:Ny-1]*dy; [Y,X] = meshgrid(ya,xa); We will do it this way. Lecture 2b Slide 20 10

Revised Plot Commands MATLAB Standard Use of imagesc() imagesc(xa,ya,a); This fails to properly convey our sense of x and y. Revised Use of imagesc() imagesc(xa,ya,a. ); >> A = zeros(4,4); >> A(2,3) = 1; >> A A = 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 >> A.' ans = 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 Lecture 2b Slide 21 Building Geometries into Data Arrays Lecture 2b 22 11

Building a Geometry? A geometry is built into an array when you can visualize the array and see the desired geometry. Suppose we wish to build a circle into this array. We fill in our array so that when the array is plotted we see our circle. Lecture 2b Slide 23 Initializing Data Arrays Nx = 10; Ny = 10; A = zeros(nx,ny); Nx = 10; Ny = 10; A = ones(nx,ny); You can initialize an array with any number: A = 3.1 * ones(nx,ny); Lecture 2b Slide 24 12

Adding Rectangles to an Array Consider adding rectangles by first computing the start and stop indices in the array, then filling in the array. nx1=3; nx2=6; A = zeros(nx,ny); ny1=4; nx1 = 3; nx2 = 6; ny1 = 4; ny2 = 8; A(nx1:nx2,ny1:ny2) = 1; ny2=8; Lecture 2b Slide 25 Centering a Rectangle It is often necessary to center a rectangle type structure in an array. % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 10; %number of cells along x Ny = 10; %number of cells along y % DEFINE RECTANGLE SIZE wx = 0.2; wy = 0.6; % COMPUTE POSITION INDICES dx = Sx/Nx; nx = round(wx/dx); nx1 = 1 + floor((nx - nx)/2); nx2 = nx1 + nx - 1; dy = Sy/Ny; ny = round(wy/dy); ny1 = 1 + round((ny - ny)/2); ny2 = ny1 + ny - 1; % CREATE A A = zeros(nx,ny); A(nx1:nx2,ny1:ny2) = 1; Lecture 2b Slide 26 13

A Simple Centered Triangle ny1 1.0 % TRIANGLE w = 0.8*Sx; h = 0.9*Sy; % CREATE CENTERED TRIANGLE ER = zeros(nx,ny); ny = round(h/dy); ny1 = 1 + floor((ny - ny)/2); ny2 = ny1 + ny - 1; for ny = ny1 : ny2 f = (ny - ny1 + 1)/(ny2 - ny1 + 1); nx = round(f*w/dx); nx1 = 1 + floor((nx - nx)/2); nx2 = nx1 + nx - 1; ER(nx1:nx2,ny) = 1; end S y nx1 h S x w nx2 ny2 Lecture 2b Slide 27 Creating Arbitrary Polygons 1.0 % DEFINE VERTICES OF POLYGON p1 = [ 0.3 ; 0.1 ]; p2 = [ 0.8 ; 0.2 ]; p3 = [ 0.7 ; 0.9 ]; p4 = [ 0.6 ; 0.4 ]; p5 = [ 0.1 ; 0.8 ]; P = [ p1 p2 p3 p4 p5 ]; % CALL POLYFILL() TO FILL % POLYGON IN ARRAY A A = polyfill(xa,ya,p); Get polyfill() from course website. Lecture 2b Slide 28 14

Circles For circles and ellipses, consider using MATLAB s meshgrid() command. % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 10; %number of cells along x Ny = 10; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); [Y,X] = meshgrid(ya,xa); % CREATE CIRCLE r = 0.4; A = (X.^2 + Y.^2) <= r^2; Lecture 2b Slide 29 Ellipses Ellipses are like circles, but have two radii. You can still use the meshgrid() command for these. % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 20; %number of cells along x Ny = 20; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); [Y,X] = meshgrid(ya,xa); % CREATE ELLIPSE rx = 0.35; ry = 0.45; A = ((X/rx).^2 + (Y/ry).^2) <= 1; Lecture 2b Slide 30 15

Offset Ellipses Ellipses and circles can be placed anywhere on the grid. % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 20; %number of cells along x Ny = 20; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); [Y,X] = meshgrid(ya,xa); % CREATE ELLIPSE xc = -0.15; yc = +0.25; rx = 0.4; ry = 0.2; A = ( ((X - xc)/rx).^2 + ((Y - yc)/ry).^2 ) <= 1; Lecture 2b Slide 31 Radial & Azimuthal Geometries Meshgrid Radial Grid RSQ = X.^2 + Y.^2; A = round(s*rsq); Radial grid lets you create circles, ellipses, rings and more. Azimuthal Grid THETA = atan2(y,x); A = round(s*theta); Azimuthal grid lets you create pie wedges and more. Lecture 2b Slide 32 16

Formed Half Spaces We can fill in half the grid under an arbitrary function like this % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 20; %number of cells along x Ny = 20; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); % CALCULATE SURFACE y = 0.2 + 0.1*cos(4*pi*xa/Sx); % FILL HALF SPACE A = zeros(nx,ny); for nx = 1 : Nx ny = round((y(nx) + Sy/2)/dy); A(nx,1:ny) = 1; end Lecture 2b Slide 33 Linear Half Spaces (1 of 2) Given two points (x 1,y 1 ) and (x 2,y 2 ), an equation for the line passing through these two points is: x y 1, 1 y y m xx 0 y y m xx 0 i i i y y m xx i i y y m x x x, y 2 1 2 1 i i Lecture 2b Slide 34 i i 1 or 2 This equation can be rearranged as y y m xx 0 i The space on one half of this line is called a half space. It is defined as: y yimxxi0 or y y mx x 0 i 17

Linear Half Spaces (2 of 2) A half space can be filled anywhere on the grid. x y 1, 1 % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 20; %number of cells along x Ny = 20; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); [Y,X] = meshgrid(ya,xa); x, y % DEFINE TWO POINTS x1 = -0.50; y1 = +0.25; x2 = +0.50; y2 = -0.25; % FILL HALF SPACE m = (y2 - y1)/(x2 - x1); A = (Y - y1) - m*(x - x1) > 0; Lecture 2b Slide 35 Creating Linear Gradients (1 of 2) The distance from a point to a line is calculated as x y 1, 1 d x, y 0 0 Two Dimensions d d x x y y x, y y y x x x y x y x y 2 1 0 2 1 0 2 1 1 2 2 1 2 1 ax by c 0 0 0 0 a b Three Dimensions d ax by c 2 1 1 0 r r r r r r 2 1 0 Lecture 2b Slide 36 18

Creating Linear Gradients (2 of 2) d y y x x x y x y x y 2 1 0 2 1 0 2 1 1 2 x x y y 2 1 2 1 d x x y y y y x x x y x y x y 2 1 0 2 1 0 2 1 1 2 2 1 2 1 y x y 1, 1 x, y y x y 1, 1 x, y x x1 = 0; y1 = 1; x2 = 2; y2 = 0; D = (y2 - y1)*x - (x2 - x1)*y + x2*y1 - x1*y2; D = abs(d)./sqrt((y2 - y1)^2 + (x2 - x1)^2); x1 = 0; y1 = 1; x2 = 2; y2 = 0; D = (y2 - y1)*x - (x2 - x1)*y + x2*y1 - x1*y2; D = D./sqrt((y2 - y1)^2 + (x2 - x1)^2); x Lecture 2b Slide 37 Creating Thick Bars We can use the linear gradients to create thick bars through our grid with any thickness and orientation. D B y x y 1, 1 y x y 1, 1 x, y x, y x x x1 = 0; y1 = 1; x2 = 2; y2 = 0; D = (y2 - y1)*x - (x2 - x1)*y + x2*y1 - x1*y2; D = abs(d)./sqrt((y2 - y1)^2 + (x2 - x1)^2); B = D < 0.7; Lecture 2b Slide 38 19

Creating Thick Bars on 3D Grids r 1 w % DEFINE TWO POINTS ALONG BAR AND WIDTH w = 0.1; r1 = [ 0.1 ; 0 ; 0.8 ]; r2 = [ 0.8 ; 1 ; 0.1 ]; r 2 % CALCULATE DISTANCE FUNCTION d = r2 - r1; d = d/norm(d); D = sqrt( (d(2)*(r1(3) - Z) - d(3)*(r1(2) - Y)).^2 +... (d(3)*(r1(1) - X) - d(1)*(r1(3) - Z)).^2 +... (d(1)*(r1(2) - Y) - d(2)*(r1(1) - X)).^2 ); ˆ r2 r1 r2 r1 d ˆ r r 1 0 % CALCULATE BAR ER = (D <= w); z z y y a ˆ x x z z aˆ y y x x a ˆ y 1 z 1 x z 1 x 1 y x 1 y 1 z 2 z z y y x x z z y y x x y 1 z 1 z 1 x 1 x 1 y 1 Lecture 2b Slide 39 Masking and Boolean Operations The figure below is the formed surfaced masked by a linear half space. FS LHS % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 20; %number of cells along x Ny = 20; %number fo cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); A [Y,X] = meshgrid(ya,xa); % CREATE A FORMED SURFACE y = -0.2 + 0.1*cos(4*pi*xa/Sx); FS = zeros(nx,ny); dy = Sy/Ny; for nx = 1 : Nx ny = round((y(nx) + Sy/2)/dy); FS(nx,ny:Ny) = 1; end % CREATE A LINEAR HALF SPACE x1 = -0.5; y1 = +0.5; x2 = +0.5; y2 = -0.5; m = (y2 - y1)/(x2 - x1); LHS = (Y - y1) - m*(x - x1) > 0; % COMBINE ABOVE GEOMETRIES A = FS.* LHS; Lecture 2b Slide 40 20

Comparison of Boolean Operations A B A + B A&B A B A.*B xor(a,b) not(a) xor(a,a&b) xor(b,a&b) Lecture 2b Slide 41 Blurring Geometries Blurring is used to resolve surfaces that slice though the middle of cells or to build more realistic device geometries. % DEFINE GRID Sx = 1; %physical size along x Sy = 1; %physical size along y Nx = 21; %number of cells along x Ny = 21; %number of cells along y % GRID ARRAYS dx = Sx/Nx; xa = [0:Nx-1]*dx; xa = xa - mean(xa); dy = Sy/Ny; ya = [0:Ny-1]*dy; ya = ya - mean(ya); [Y,X] = meshgrid(ya,xa); % CREATE A CROSS ER = abs(x)<=0.075 abs(y)<=0.075; % CREATE BLUR FUNCTION B = exp(-(x.^2 + Y.^2)/0.1^2); % PERFORM BLUR OPERATION ER = fft2(er).*fft2(b)/sum(b(:)); ER = ifftshift(real(ifft2(er))); % PERFORM THRESHOLD OPERATION ER = ER > 0.4; Lecture 2b Slide 42 21

Scaling the Values of the Data Eventually, we need to build devices on a grid. This is done by a dielectric constant to specific geometries in the array. Typically, the background will be air with a dielectric constant of 1.0. er1 = 1.0; er2 = 2.4; A = er1*(1-a) + er2*a; A = er1 + (er2 er1)*a; Lecture 2b Slide 43 22