########################################################################## # Scriptfile: usr_extrude_poly.lsf # # Description: This file will extrude a selected polygon # with a desired sidewall angle. The polygon # retains the same original height. # # # Copyright 2007, Lumerical Solutions, Inc. ########################################################################### # choose the sidewall angle (in degrees) sidewall_angle = 80; # degrees # choose to extrude upwards or downwards (use 1 for up or -1 for down) extrude_direction = 1; # choose the approximate value of dz # this is used to determine how many steps are required for the polygon dz = 25e-9; # find out how many of the selected objects have "vertices" property #n = getsize("vertices"); n=1; # warn the user and break if n != 1 if(n == 0) { ?"No polygon is selected"; break; } if(n > 1) { ?"Please select a single polygon for extrusion"; break; } # get the vertices, min z and max z V = get("vertices"); z1 = get("z min"); z2 = get("z max"); # calculate the number of vertices and the number steps required num_vertices= length(V)/2; num_steps = round((z2-z1)/dz); if(num_steps < 2) { num_steps = 2; } # calculate the mean center of the vertices and the average "radius" tempVx = pinch(V,2,1); tempVy = pinch(V,2,2); x0 = sum(tempVx)/num_vertices; y0 = sum(tempVy)/num_vertices; r0 = sum( sqrt(((tempVx-x0)^2 + (tempVy-y0)^2)) )/num_vertices; # increase x and y scales of the vertices, by linearly increasing the # average "radius" for(j=1:num_steps) { scale_factor = ( r0 + (j-1/2)*(z2-z1)/num_steps/tan(sidewall_angle*pi/180) )/r0; tempVx = (pinch(V,2,1)-x0)*scale_factor + x0; tempVy = (pinch(V,2,2)-y0)*scale_factor + y0; tempV = V; tempV(1:num_vertices,1) = tempVx; tempV(1:num_vertices,2) = tempVy; # only add a new polygon after the first one has been modified if(j > 1) { copy(0,0,0); } if(extrude_direction > 0) { set("z min",z1+(j-1)*(z2-z1)/num_steps); set("z max",z1+j*(z2-z1)/num_steps); } else { set("z min",z2-j*(z2-z1)/num_steps); set("z max",z2-(j-1)*(z2-z1)/num_steps); } set("vertices",tempV); } selectall; addtogroup('extruded polygon');