Computational Design + Fabrication:...

Post on 23-May-2018

220 views 0 download

Transcript of Computational Design + Fabrication:...

Computational Design + Fabrication: Geometry

Jonathan Bachrach

EECS UC Berkeley

September 1, 2015

Today 1

who are you?trigonometrygeometrysolid geometrytools

Who Are You? 2

nameundergraduate or graduatemajorpython programming?courses taken ( PL, graphics, geometry )cad tools?proficient in any shop tools?cnc tools?favorite project most proud ofwhy taking class?

Reading 0 3

the future of design by lipson et alquestions

Pythagoras’ Theorem 4

right angled triangle

a2 + b2 = c2 (1)

a

b

c

Transcendentals 5

sinA = oppositehypotenuse = a

c

cosA = adjacenthypotenuse = b

c

tanA = oppositeadjacent =

ab = sinA

cosA

hypotenuse

adjacent

opposite

A

B

C

ca

b

Vector 6

v = [a,b]magnitude = |v | =

√a2 + b2

direction

direction

magnitude

vector

Vector Ops 7

normalizeaddscale

Vector Normalize 8

unit vectorv = v/|v |

unitvector

v

length

= v / |v|

Vector Add 9

w = u + v

u

v

u+v

Vector Scale 10

w = s ∗ v

v

3 |v|

3v

Vector Dot 11

w = u · vu · v = |u| × |v | × cos θdot product of vectors at right angle is zero

t

cos(t) * v

v

u

Vector Cross 12

w = u × vu × v = |u||v | sin θnright hand rule: u = index finger, v = middle finger, w = thumb

a

b

a x b

Vector Conversions 13

polar to cartesian: v = r [cos θ, sin θ]cartesian to polar: [r , θ] = [norm(v),atan2(v)]

Point as Vector 14

interpreted as vector from zerosubtracting points forms vector

v = [a,b]

(a, b)

(0, 0)

Line 15

infinitethrough two pointsparameterized by t

p

v

Ray 16

one half of line bounded by point

p

v

LineSegment 17

finite line bounded by points

p_0

p_1

PolyLine 18

collection of lines segments connecting pointsopen and closedcollection of polylinesDXF, SVG

p_0

p_1

p_3

p_2

Plane 19

n · (p − p0) = 0 (2)

point p0

normal ndot product interpretationintersect linenearest point

n

p p_0

Polygon 20

closed polylineperimeterarea

concave convex

Basic Polygons 21

trianglesquare

Non Polygons 22

circlesquiggly

Approximating Non-Polygons by Polygons 23

circleapproximation error

Approximation Error 24

number of facetsanglefragment sizesquared area delta

Hausdorff Distance 25

two polygons are close if every point in one is close to the othermax distance from one polygon to closest point in the othercould be computed using sampling

Triangulation of Polygons 26

break polygon into neighboring triangleshow do we do this?what do we care about in triangulating?ear clipping – triangle with one edge insidefaster algorithms

Polygon Area 27

clockwisesum area under successive pointsreverse sign if xi+1 < xi

how else?

+ -

Polyhedra 28

collection of intersecting planesneighboring polygons called faces forming closedhow do we know its closed?

Rhombictriacontahedron by DTR Tetrahedron by Robert Webb’s Stella software

Simple Polyhedra 29

tetrahedroncube

Tetrahedron by Robert Webb’s Stella software

Non Polyhedra 30

spherecylinder

Approximating Non Polyhedra with Polyhedra 31

spherecylinderapproximation erroradvantages?problems?

Planetary-Scale Terrain Composition – Kooima + Leigh + Johnson + Roberts + SubbaRao + DeFanti

Mesh Datastructures 32

stl: faces with redundant pointsobj: points faces with point indices( winged mesh )

Affine Transformations 33

translatescalerotate( shear )

Translate 34

translation vector

Scale 35

scaling from origin

Rotate 36

rotation about origin

Affine Transformation Matrices 37

2x23x3basic transformationscompositionextends to 3D

2x2 Affine Transformation Matrices 38

∣∣∣∣x2y2

∣∣∣∣ = A×∣∣∣∣x1y1

∣∣∣∣+ B (3)

2x2 Identity 39

A =

∣∣∣∣1 00 1

∣∣∣∣ ,B =

∣∣∣∣00∣∣∣∣ (4)

2x2 Scaling 40

A =

∣∣∣∣sx 00 sy

∣∣∣∣ ,B =

∣∣∣∣00∣∣∣∣ (5)

2x2 Rotation 41

A =

∣∣∣∣cos θ − sin θsin θ cos θ

∣∣∣∣ ,B =

∣∣∣∣00∣∣∣∣ (6)

2x2 Translation 42

A =

∣∣∣∣0 00 0

∣∣∣∣ ,B =

∣∣∣∣txty∣∣∣∣ (7)

Homogenous Coordinates 43

can write entire affine transformation in one matrixcan compute inverse of transformationaugment input vector with 1

∣∣∣∣∣∣x2y21

∣∣∣∣∣∣ =

∣∣∣∣∣∣a b txc d ty0 0 1

∣∣∣∣∣∣∣∣∣∣∣∣x1y11

∣∣∣∣∣∣ (8)

v2 = M × v1 (9)

Composition 44

now can compose transformations using matrix multiplication

MA = MR ×MT (10)∣∣∣∣∣∣cos θ − sin θ txsin θ cos θ ty

0 0 1

∣∣∣∣∣∣ =

∣∣∣∣∣∣cos θ − sin θ 0sin θ cos θ 0

0 0 1

∣∣∣∣∣∣×∣∣∣∣∣∣1 0 tx0 1 ty0 0 1

∣∣∣∣∣∣ (11)

Solid Geometry 45

3D shapes with volumeset opsoffset, convex hull, minkowski sum2D to 3D3D to 2D

Set Ops 46

interpretation of solids as sets of pointsops: union, intersection, difference

Union 47

sometimes written using addition

A

B

A + B

Intersection 48

sometimes written using multiplication

A

B

A * B

Difference 49

sometimes written using subtraction

A

B

A - B

Offset 50

amountchamferhow to implement?

Convex Hull 51

definitionargumentsexamples

Minkowski Sum 52

definitionargumentsexamples

2D to 3D 53

ExtrusionLathe

Extrusion 54

heightscalarotate

Lathe 55

must translate off center

3D to 2D 56

shadowslice

Constructive Solid Geometry (CSG) 57

picture by N.Goodger

CSG Hierarchy 58

chang + woodbury

CSG Data Structure 59

OpenSCAD Cheatsheet 60outputs stlproceduralbased on CGAL nef polyhedra

www.openscad.org

2D Primitives 61

circle(radius | d=diameter)

square(size,center)

square([width,height],center)

polygon([points])

polygon([points],[paths])

text(t, size, font, halign, valign, spacing, direction, language, script)

square(center=true);

2D to 3D Extrusion 62

linear_extrude(height,center,convexity,twist,slices)

rotate_extrude(convexity)

linear_extrude(height = 2) square(center=true);

3D Primitives 63

sphere(radius | d=diameter)

cube(size)

cube([width,depth,height])

cylinder(h,r|d,center)

cylinder(h,r1|d1,r2|d2,center)

polyhedron(points, triangles, convexity)

cube(r = 1, center = true);

Transformations 64

translate([x,y,z])

rotate([x,y,z])

scale([x,y,z])

resize([x,y,z],auto)

color([r,g,b,a])

translate([0, 0, 1.5]) cube(r = 1, center = true);

Operations 65

mirror([x,y,z])

offset(r|delta,chamfer)

hull()

minkowski()

hull() {

translate([15,10,0]) circle(10);

circle(10);

}

CSG 66

union()

difference()

intersection()

difference() {

cylinder (h = 4, r=1, center = true, $fn=100);

rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);

}

Math 67

sin

cos

tan

acos

asin

atan

atan2

floor

round

ceil

abs

sign

ln

len

let

log

pow

sqrt

exp

rands

min

max

loops 68

for (i = [start:end]) { ... }

for (i = [start:step:end]) { ... }

for (i = [...,...,...]) { ... }

intersection_for(i = [start:end]) { ... }

intersection_for(i = [start:step:end]) { ... }

intersection_for(i = [...,...,...]) { ... }

for(i=[0:36])

translate([i*10,0,0])

cylinder(r=5,h=cos(i*10)*50+60);

variable 69

var = value;

assign (...) { ... }

for (i = [10:50]) {

angle = i*360/20;

distance = i*10;

r = i*2;

rotate(angle, [1, 0, 0])

translate([0, distance, 0])

sphere(r = r);

}

conditionals 70

if (...) { ... }

if (x > y) {

cube(size = 1, center = false);

} else {

cube(size = 2, center = true);

}

modules / functions 71

module name(...) { ... }

name();

function name(...) = ...

name();

module hole(distance, rot, size) {

rotate(a = rot, v = [1, 0, 0]) {

translate([0, distance, 0]) {

cylinder(r = size, h = 100, center = true);

}

}

}

hole(0, 90, 10);

next time 72

Our software stackCNC machines and manufacturing

Referencers 73

ILM Math Library – http://www.openexr.com

Open SCAD – http://www.openscad.org