Python. High-level General-purpose Dynamic Readable Multi-paradigm Portable

Similar documents
LOWELL WEEKLY JOURNAL

Two Posts to Fill On School Board

LOWELL WEEKLY JOURNAL

A DARK GREY P O N T, with a Switch Tail, and a small Star on the Forehead. Any

County Council Named for Kent

OWELL WEEKLY JOURNAL

A. H. Hall, 33, 35 &37, Lendoi

MA Spring 2013 Lecture Topics

UNC Charlotte Super Competition Level 3 Test March 4, 2019 Test with Solutions for Sponsors

12. Stresses and Strains

Practice Midterm 2 Math 2153

Midterm 1 Solutions Thursday, February 26

CONTENTS COLLEGE ALGEBRA: DR.YOU

POLYNOMIALS. x + 1 x x 4 + x 3. x x 3 x 2. x x 2 + x. x + 1 x 1

Department of mathematics MA201 Mathematics III

Section Summary. Section 1.5 9/9/2014

P A L A C E P IE R, S T. L E O N A R D S. R a n n o w, q u a r r y. W WALTER CR O TC H, Esq., Local Chairman. E. CO O PER EVANS, Esq.,.

Math 23b Practice Final Summer 2011

1 Arithmetic calculations (calculator is not allowed)

Lecture Predicates and Quantifiers 1.5 Nested Quantifiers

LOWELL JOURNAL. MUST APOLOGIZE. such communication with the shore as Is m i Boimhle, noewwary and proper for the comfort

1. A polynomial p(x) in one variable x is an algebraic expression in x of the form

Chain Rule. MATH 311, Calculus III. J. Robert Buchanan. Spring Department of Mathematics

Practice Test III, Math 314, Spring 2016

Without fully opening the exam, check that you have pages 1 through 12.

Multivariable Calculus and Matrix Algebra-Summer 2017

LOWELL WEEKLY JOURNAL

Introduction to Predicate Logic Part 1. Professor Anita Wasilewska Lecture Notes (1)

No calculators, cell phones or any other electronic devices can be used on this exam. Clear your desk of everything excepts pens, pencils and erasers.

Formulas to remember

Sec. 14.3: Partial Derivatives. All of the following are ways of representing the derivative. y dx

Concept of a basis. Based on this treatment we can assign the basis to one of the irreducible representations of the point group.

LOWELL WEEKLY JOURNAL. ^Jberxy and (Jmott Oao M d Ccmsparftble. %m >ai ruv GEEAT INDUSTRIES

MATHEMATICS AS/M/P1 AS PAPER 1

Jim Lambers MAT 280 Summer Semester Practice Final Exam Solution. dy + xz dz = x(t)y(t) dt. t 3 (4t 3 ) + e t2 (2t) + t 7 (3t 2 ) dt

Some Basic Logic. Henry Liu, 25 October 2010

Intro Vectors 2D implicit curves 2D parametric curves. Graphics 2012/2013, 4th quarter. Lecture 2: vectors, curves, and surfaces

Predicate Logic. Andreas Klappenecker

MATH 452. SAMPLE 3 SOLUTIONS May 3, (10 pts) Let f(x + iy) = u(x, y) + iv(x, y) be an analytic function. Show that u(x, y) is harmonic.

LOWELL WEEKLY JOURNAL.

Predicate Logic. CSE 191, Class Note 02: Predicate Logic Computer Sci & Eng Dept SUNY Buffalo

2. Second-order Linear Ordinary Differential Equations

' Liberty and Umou Ono and Inseparablo "

Implicit Differentiation

16.3 Conservative Vector Fields

Lecture 13 - Wednesday April 29th

PALACE PIER, ST. LEONARDS. M A N A G E R - B O W A R D V A N B I E N E.

(D) (A) Q.3 To which of the following circles, the line y x + 3 = 0 is normal at the point ? 2 (A) 2

Module Two: Differential Calculus(continued) synopsis of results and problems (student copy)

" W I T H M: A. L I G E T O ' W ^ P L D IST O ISTE -A-IsTD G H! A-I^IT Y IPO PL A.LI-i. :

DISCUSSION CLASS OF DAX IS ON 22ND MARCH, TIME : 9-12 BRING ALL YOUR DOUBTS [STRAIGHT OBJECTIVE TYPE]

ALGEBRA II WITH TRIGONOMETRY EXAM

MANY BILLS OF CONCERN TO PUBLIC

L bor y nnd Union One nnd Inseparable. LOW I'LL, MICHIGAN. WLDNHSDA Y. JULY ), I8T. liuwkll NATIdiNAI, liank

Math Practice Exam 3 - solutions

Instructions: No books. No notes. Non-graphing calculators only. You are encouraged, although not required, to show your work.

FFTs in Graphics and Vision. Homogenous Polynomials and Irreducible Representations

MATHS 267 Answers to Stokes Practice Dr. Jones

Math 2E Selected Problems for the Final Aaron Chen Spring 2016

Solutions to Sample Questions for Final Exam

Engg. Math. I. Unit-I. Differential Calculus

Additional Practice Lessons 2.02 and 2.03

SBE MINIMAL REQUIREMENTS

MTH4101 CALCULUS II REVISION NOTES. 1. COMPLEX NUMBERS (Thomas Appendix 7 + lecture notes) ax 2 + bx + c = 0. x = b ± b 2 4ac 2a. i = 1.

Functions and Equations

Part I: Propositional Calculus

MAC2313 Final A. (5 pts) 1. How many of the following are necessarily true? i. The vector field F = 2x + 3y, 3x 5y is conservative.

oenofc : COXT&IBCTOEU. AU skaacst sftwer thsa4 aafcekr will be ehat«s«ai Bi. C. W. JUBSSOS. PERFECT THBOUGH SDFFEBISG. our

MY PUTNAM PROBLEMS. log(1 + x) dx = π2

Recall that the expression x > 3 is not a proposition. Why?

Chapter 2. First-Order Partial Differential Equations. Prof. D. C. Sanyal

Intro Vectors 2D implicit curves 2D parametric curves. Graphics 2011/2012, 4th quarter. Lecture 2: vectors, curves, and surfaces

MAS223 Statistical Inference and Modelling Exercises

Section A. A 5 12 sin cm. AC cos100 7 M15/5/MATHL/HP2/ENG/TZ2/XX/M. 1. (a) (M1) A1 [2 marks] (b) (M1) therefore AC 13.

Lecture Notes on Partial Dierential Equations (PDE)/ MaSc 221+MaSc 225

THE LOGIC OF QUANTIFIED STATEMENTS. Predicates and Quantified Statements I. Predicates and Quantified Statements I CHAPTER 3 SECTION 3.

NATIONAL ACADEMY DHARMAPURI TRB MATHEMATICS DIFFERENTAL EQUATIONS. Material Available with Question papers CONTACT ,

gap> G:=ReducedGroebnerBasis(B,MonomialGrlexOrdering(y,x)); [ x^2-x, x*y-x, y^2-x ]

King Fahd University of Petroleum and Minerals Prep-Year Math Program Math Term 161 Recitation (R1, R2)

Automatic differentiation with Perl

M273Q Multivariable Calculus Spring 2017 Review Problems for Exam 3

SOLUTIONS FOR ADMISSIONS TEST IN MATHEMATICS, COMPUTER SCIENCE AND JOINT SCHOOLS WEDNESDAY 31 OCTOBER 2018

JUST THE MATHS UNIT NUMBER PARTIAL DIFFERENTIATION 1 (Partial derivatives of the first order) A.J.Hobson

MS 3011 Exercises. December 11, 2013

Math 212-Lecture 8. The chain rule with one independent variable

6 Second Order Linear Differential Equations

Number Theory and Graph Theory

PUTNAM TRAINING POLYNOMIALS. Exercises 1. Find a polynomial with integral coefficients whose zeros include

Name: Class: Date: = 30.6 and t 15. = 125 D. t 21 = 20 = 3.75, S 6

Bi. lkent Calculus II Exams

Math 207 Honors Calculus III Final Exam Solutions

MIDTERM EXAMINATION. Spring MTH301- Calculus II (Session - 3)

Core Mathematics C12

This lecture: basis and dimension 4.4. Linear Independence: Suppose that V is a vector space and. r 1 x 1 + r 2 x r k x k = 0

Core Mathematics C12

CS156: The Calculus of Computation Zohar Manna Winter 2010

Math 223 Final. July 24, 2014

Let s estimate the volume under this surface over the rectangle R = [0, 4] [0, 2] in the xy-plane.

[STRAIGHT OBJECTIVE TYPE] log 4 2 x 4 log. x x log 2 x 1

Function Expressions

Transcription:

Python High-level General-purpose Dynamic Readable Multi-paradigm Portable

Pre-Defined Functions Python x + y x * y x - y x / y x**y abs(x) sqrt(x) exp(x) pow(x, y) log(x) sin(x) atan(x) atan2(y, x) floor(x) Matematics x + y x y x y x/y x y x x e x x y log x sin x atan x atan y x x

From Mathematics to Python 1 2 + 3 + sin 5 2 2

From Mathematics to Python 1 2 + 3 + sin 5 2 2 1/2 + sqrt(3) + sin(2)**(5/2)

From Mathematics to Python 1 2 + 3 + sin 5 2 2 1/2 + sqrt(3) + sin(2)**(5/2) cos4 2 5 atan 3

From Mathematics to Python 1 2 + 3 + sin 5 2 2 1/2 + sqrt(3) + sin(2)**(5/2) cos4 2 5 atan 3 (cos(2/sqrt(5))**4)/atan(3)

From Mathematics to Python 1 2 + 3 + sin 5 2 2 1/2 + sqrt(3) + sin(2)**(5/2) cos4 2 5 atan 3 (cos(2/sqrt(5))**4)/atan(3) 1 log 2 (3 9 log 25)

From Mathematics to Python 1 2 + 3 + sin 5 2 2 1/2 + sqrt(3) + sin(2)**(5/2) cos4 2 5 atan 3 (cos(2/sqrt(5))**4)/atan(3) 1 log 2 (3 9 log 25) sqrt(1/log(2**abs(3-9*log(25))))

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5)))

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5))) log sin(2 + atan π 5 )

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5))) log sin(2 + atan π 5 ) cos(cos(cos(0.5)))**5

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5))) log sin(2 + atan π 5 ) cos(cos(cos(0.5)))**5 cos 5 cos cos 0.5

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5))) log sin(2 + atan π 5 ) cos(cos(cos(0.5)))**5 cos 5 cos cos 0.5 sin(cos(sin(pi/3)/3)/3)

From Python to Mathematics log(sin(2 + floor(atan(pi))/sqrt(5))) log sin(2 + atan π 5 ) cos(cos(cos(0.5)))**5 cos 5 cos cos 0.5 sin(cos(sin(pi/3)/3)/3) sin cos sin π 3 3 3

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python:

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python: def f(x): return x*x

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python: def f(x): return x*x > f(3)

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python: def f(x): return x*x > f(3) 9

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python: def f(x): return x*x > f(3) 9 > f(5)

From Mathematics to Python Function A mapping between arguments and results The mapping is implicit, as it is computed when the function is applied to a set of arguments and returns the result of the computation A function accepts arguments and returns results Example: f(x) = x x Python: def f(x): return x*x > f(3) 9 > f(5) 25

Arithmetic in Python A number can be: Integral Rational Real Complex Number

Arithmetic in Python A number can be: Integral Rational Real Complex Number A number can also be: Exact Inexact Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact

Arithmetic in Python A number can be: Integral Rational Real Complex Number A number can also be: Exact Inexact Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact All inexact numbers above a pre-defined limit are infinite and cause an error

Arithmetic in Python A number can be: Integral Rational Real Complex Number A number can also be: Exact Inexact Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact All inexact numbers above a pre-defined limit are infinite and cause an error Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact

Arithmetic in Python A number can be: Integral Rational Real Complex Number A number can also be: Exact Inexact Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact All inexact numbers above a pre-defined limit are infinite and cause an error Inexactness is contagious: whenever an inexact number is used in an operation, the result is inexact Python uses the word float for inexact numbers

Arithmetic in Python Exact Numbers > 10*10

Arithmetic in Python Exact Numbers > 10*10 10000000000

Arithmetic in Python Exact Numbers > 10*10 10000000000 > 10*100

Arithmetic in Python Exact Numbers > 10*10 10000000000 > 10*100 100000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000

Arithmetic in Python Exact Numbers > 10*10 10000000000 > 10*100 100000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000 > 10**1000

Arithmetic in Python Exact Numbers > 10*10 10000000000 > 10*100 100000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000 > 10**1000 100000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000

Arithmetic in Python Inexact Numbers > 10.0**10

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0 > 10.0**100

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0 > 10.0**100 1e+100

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0 > 10.0**100 1e+100 > 10.0**1000

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0 > 10.0**100 1e+100 > 10.0**1000 OverflowError: 'Result too large'

Arithmetic in Python Inexact Numbers > 10.0**10 10000000000.0 > 10.0**100 1e+100 > 10.0**1000 OverflowError: 'Result too large' Inexact numbers have limited size and limited precision But they are much more efficient to compute There are no solutions, only trade-offs

Arithmetic in Python Rounding Errors > (4/3-1)*3-1

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9) 0.999755859375

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9) 0.999755859375 > f(19843566622234755.9)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9) 0.999755859375 > f(19843566622234755.9) 0.0

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9) 0.999755859375 > f(19843566622234755.9) 0.0 > f(553774558711019983333.9)

Arithmetic in Python Rounding Errors > (4/3-1)*3-1 -2.220446049250313e-16 Dramatic Example: f(x) = x 0.1 (10 x 10) > def f(x): return x - 0.1*(10*x - 10) > f(5.1) 0.9999999999999991 > f(176498634.7) 0.9999999701976776 > f(1209983553611.9) 0.999755859375 > f(19843566622234755.9) 0.0 > f(553774558711019983333.9) -65536.0

Conditional Expressions x = { x, if x < 0 x, otherwise.

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression An expression whose value depends on one or more conditions if α, return β, else return γ

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression An expression whose value depends on one or more conditions if α, return β, else return γ return β if α, else γ

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression An expression whose value depends on one or more conditions if α, return β, else return γ return β if α, else γ α is the condition, β is the consequent, γ is the alternative

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression An expression whose value depends on one or more conditions if α, return β, else return γ return β if α, else γ α is the condition, β is the consequent, γ is the alternative Logical Expression An expression whose value is either true or false α is a logical expression

Conditional Expressions Logical Value x = { x, if x < 0 x, otherwise. True or False In Python: True, False False, None, 0, (and others) are considered false, anything else is considered true (including True) Conditional expressions use the logical value of the condition to evaluate the correct choice

Conditional Expressions x = { x, if x < 0 x, otherwise. Predicate A function (or operator) that always returns true or false < is a predicate Relational Operator A predicate that compares entities <, >, =,,, and are relational operator In Python: <, >, ==, <=, >= and!=

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression return β if α else γ

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression return β if α else γ if α, return β, else return γ

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression return β if α else γ if α, return β, else return γ Python: def abs(x): return -x if x < 0 else x

Conditional Expressions x = { x, if x < 0 x, otherwise. Conditional Expression return β if α else γ if α, return β, else return γ Python: def abs(x): return -x if x < 0 else x def abs(x): if x < 0: return -x else: return x

Conditional Expressions Python: max(x, y) = def max(x, y): return x if x > y else y { x, if x > y y, otherwise.

Conditional Expressions Python: max(x, y) = def max(x, y): return x if x > y else y def max(x, y): if x > y: return x else: return y { x, if x > y y, otherwise.

Conditional Expressions 1 if x < 0 sgn x = 0 if x = 0 1 otherwise

Conditional Expressions 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise

Conditional Expressions Python: 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise

Conditional Expressions Python: 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise def signum(x): return -1 if x < 0 else 0 if x == 0 else 1

Conditional Expressions Python: 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise def signum(x): return -1 if x < 0 else (0 if x == 0 else 1)

Conditional Expressions Python: def signum(x): if x < 0: return -1 else: if x == 0: return 0 else: return 1 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise

Conditional Expressions Python: def signum(x): if x < 0: return -1 elif x == 0: return 0 else: return 1 1 if x < 0 sgn x = 0 if x = 0 1 otherwise 1 { if x < 0 sgn x = 0 if x = 0 otherwise 1 otherwise

Local Variables c b. a

Local Variables c b. a Heron s formula A = s (s a) (s b) (s c) where s = a + b + c 2

Local Variables Heron s formula A = s (s a) (s b) (s c) where s = a + b + c 2 Local Variable s is a local variable A local variable is an additional name That abstracts concepts That simplifies expressions That avoids repeated computations

Local Variables Heron s formula A = s (s a) (s b) (s c) where s = a + b + c 2 def triangle_area(a, b, c): s = (a + b + c)/2 return sqrt(s*(s - a)*(s - b)*(s - c))

Local Variables Heron s formula A = s (s a) (s b) (s c) where s = a + b + c 2 def triangle_area(a, b, c): s = (a + b + c)/2 return sqrt(s*(s - a)*(s - b)*(s - c)) Local Variable A variable is defined the first time it is given a value The scope of the variable is the function that contains its definition

Global Variables pi = 3.14159 def area_circle(r): return pi*r*r

Global Variables pi = 3.14159 def area_circle(r): return pi*r*r Global Variable A local variable is visible only in the function where it is defined A global variable is visible in the entire program The definition of global variables is identical to the definition of local variables, but they must be defined outside any function definition In most cases, global variables should be constants

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules import math

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules import math math.sqrt(2) + math.sin(math.pi)

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules import math as m m.sqrt(2) + m.sin(m.pi)

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules from math import sqrt, sin sqrt(2) + sin(math.pi)

Modules Every time Python is restarted, it starts in a clean state All definitions made before are lost In order to save them, put them in a file (called a module) We import the module to regain the definitions Most of Python is stored in modules from math import * sqrt(2) + sin(pi)

Modules import khepri khepri.box(khepri.xyz(2,1,1), khepri.xyz(3,4,5)) khepri.cone(khepri.xyz(6,0,0), 1, khepri.xyz(8,1,5)) khepri.cone_frustum(khepri.xyz(11,1,0), 2, khepri.xyz(10,0,5), 1) khepri.sphere(khepri.xyz(8,4,5), 2) khepri.cylinder(khepri.xyz(8,7,0), 1, khepri.xyz(6,8,7)) khepri.regular_pyramid(5, khepri.xyz(-2,1,0), 1, 0, khepri.xyz(2,7,7)) khepri.torus(khepri.xyz(14,6,5), 2, 1)

Modules import khepri as kh kh.box(kh.xyz(2,1,1), kh.xyz(3,4,5)) kh.cone(kh.xyz(6,0,0), 1, kh.xyz(8,1,5)) kh.cone_frustum(kh.xyz(11,1,0), 2, kh.xyz(10,0,5), 1) kh.sphere(kh.xyz(8,4,5), 2) kh.cylinder(kh.xyz(8,7,0), 1, kh.xyz(6,8,7)) kh.regular_pyramid(5, kh.xyz(-2,1,0), 1, 0, kh.xyz(2,7,7)) kh.torus(kh.xyz(14,6,5), 2, 1)

Modules from khepri import * box(xyz(2,1,1), xyz(3,4,5)) cone(xyz(6,0,0), 1, xyz(8,1,5)) cone_frustum(xyz(11,1,0), 2, xyz(10,0,5), 1) sphere(xyz(8,4,5), 2) cylinder(xyz(8,7,0), 1, xyz(6,8,7)) regular_pyramid(5, xyz(-2,1,0), 1, 0, xyz(2,7,7)) torus(xyz(14,6,5), 2, 1)

Cartesian Coordinates Z Y P. z x y X

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(px, py, pz, qx, qy, qz): return sqrt((qx-px)**2 + (qy-py)**2 + (qz-pz)**2)

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(px, py, pz, qx, qy, qz): return sqrt((qx-px)**2 + (qy-py)**2 + (qz-pz)**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(2, 1, 3, 5, 6, 4) 5.916079783099616

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(px, py, pz, qx, qy, qz): return sqrt((qx-px)**2 + (qy-py)**2 + (qz-pz)**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(2, 1, 3, 5, 6, 4) 5.916079783099616 It is not as clear as in mathematics

Cartesian Coordinates Intermediate Point The Intermediate point between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is ( p x + q x 2, p y + q y 2, p z + q z ) 2

Cartesian Coordinates Intermediate Point The Intermediate point between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is ( p x + q x 2, p y + q y 2, p z + q z ) 2 def intermediate_point(px, py, pz, qx, qy, qz): return...(px+qx)/2, (py+qy)/2, (pz+qz)/2...

Cartesian Coordinates Intermediate Point The Intermediate point between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is ( p x + q x 2, p y + q y 2, p z + q z ) 2 def intermediate_point(px, py, pz, qx, qy, qz): return...(px+qx)/2, (py+qy)/2, (pz+qz)/2... We need to handle coordinates as an entity, and not as triplets of numbers

Cartesian Coordinates from khepri import *

Cartesian Coordinates from khepri import * > xyz(1, 2, 3)

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3)

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3))

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1 > cy(xyz(1, 2, 3))

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1 > cy(xyz(1, 2, 3)) 2

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1 > cy(xyz(1, 2, 3)) 2 > cz(xyz(1, 2, 3))

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1 > cy(xyz(1, 2, 3)) 2 > cz(xyz(1, 2, 3)) 3 cx(xyz(x, y, z)) = x cy(xyz(x, y, z)) = y cz(xyz(x, y, z)) = z

Cartesian Coordinates from khepri import * > xyz(1, 2, 3) xyz(1, 2, 3) > cx(xyz(1, 2, 3)) 1 > cy(xyz(1, 2, 3)) 2 > cz(xyz(1, 2, 3)) 3 cx(xyz(x, y, z)) = x cy(xyz(x, y, z)) = y cz(xyz(x, y, z)) = z Operations for Cartesian Coordinates xyz is the constructor cx, cy, and cz, are the selectors

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(px, py, pz, qx, qy, qz): return sqrt((qx-px)**2 + (qy-py)**2 + (qz-pz)**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(2, 1, 3, 5, 6, 4) 5.916079783099616

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(p, q): return sqrt((qx?-px?)**2 + (qy?-py?)**2 + (qz?-pz?)**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(xyz(2, 1, 3), xyz(5, 6, 4)) 5.916079783099616

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(p, q): return sqrt((cx(q)-cx(p))**2+(cy(q)-cy(p))**2+(cz(q)-cz(p))**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(xyz(2, 1, 3), xyz(5, 6, 4)) 5.916079783099616

Cartesian Coordinates Distance The distance d between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is d = (q x p x ) 2 + (q y p y ) 2 + (q z p z ) 2 def distance(p, q): return sqrt((q.x-p.x)**2 + (q.y-p.y)**2 + (q.z-p.z)**2) The distance between P = (2, 1, 3) and Q = (5, 6, 4) is > distance(xyz(2, 1, 3), xyz(5, 6, 4)) 5.916079783099616

Cartesian Coordinates Intermediate Point The Intermediate point P m between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is P m = ( p x + q x 2, p y + q y 2, p z + q z ) 2 def intermediate_point(px, py, pz, qx, qy, qz): return...(px+qx)/2, (py+qy)/2, (pz+qz)/2...

Cartesian Coordinates Intermediate Point The Intermediate point P m between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is P m = ( p x + q x 2, p y + q y 2, p z + q z ) 2 def intermediate_point(p, q): return xyz((cx(p)+cx(q))/2, (cy(p)+cy(q))/2, (cz(p)+cz(q))/2)

Cartesian Coordinates Intermediate Point The Intermediate point P m between P = (p x, p y, p z ) and Q = (q x, q y, q z ) is P m = ( p x + q x 2, p y + q y 2, p z + q z ) 2 def intermediate_point(p, q): return xyz((p.x+q.x)/2, (p.y+q.y)/2, (p.z+q.z)/2)

Cartesian Coordinates > xy(1, 2)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2) xyz(0, 2, 0)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2) xyz(0, 2, 0) > z(3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2) xyz(0, 2, 0) > z(3) xyz(0, 0, 3)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2) xyz(0, 2, 0) > z(3) xyz(0, 0, 3) def xy(x, y): return xyz(x, y, 0) def xz(x, z): return xyz(x, 0, z) def yz(y, z): return xyz(0, y, z)

Cartesian Coordinates > xy(1, 2) xyz(1, 2, 0) > yz(2, 3) xyz(0, 2, 3) > xz(1, 3) xyz(1, 0, 3) > x(1) xyz(1, 0, 0) > y(2) xyz(0, 2, 0) > z(3) xyz(0, 0, 3) def xy(x, y): return xyz(x, y, 0) def xz(x, z): return xyz(x, 0, z) def yz(y, z): return xyz(0, y, z) def x(x): return xyz(x, 0, 0) def y(y): return xyz(0, y, 0) def z(z): return xyz(0, 0, z)

Cartesian Coordinates Example: Min. number of risers for max. riser of 0.18? Y P 1 X.... P 0

Cartesian Coordinates Example: Min. number of risers for max. riser of 0.18? Y P 1 X.... P 0 def minimum_number_of_steps(p0, p1): return ceil((cy(p1) - cy(p0))/0.18)

Cartesian Coordinates Example: Min. number of risers for max. riser of 0.18? Y P 1 X.... P 0 def minimum_number_of_steps(p0, p1): return ceil((p1.y - p0.y)/0.18)

Cartesian Coordinates Translation Z P Y. X

Cartesian Coordinates Translation Z P Y z. x y X

Cartesian Coordinates Translation Z P P Y z. x y X

Cartesian Coordinates Translation Z P P Y z z z. x x y y y X

Cartesian Coordinates Translation Z P V Y P z z z. x x y y y X

Cartesian Coordinates Translation Z P V Y P z V z z. x x y y y X

Cartesian Coordinates Translation Z P V Y P z V z. x x z y y z y X x y

Cartesian Coordinates Translation Z P V Y P z V z. x x z y y z y X x y P = P + V

Cartesian Coordinates Translation Z P V Y P z V z. x x z y y z y X x y V = P P

Cartesian Coordinates Vectors A vector represents a displacement A vector does not represent a location A vector does not have an origin or a destination A vector is created by the constructor vxyz

Cartesian Coordinates Vectors A vector represents a displacement A vector does not represent a location A vector does not have an origin or a destination A vector is created by the constructor vxyz def vxy(dx, dy): return vxyz(dx, dy, 0) def vxz(dx, dz): return vxyz(dx, 0, dz) def vyz(dy, dz): return vxyz(0, dy, dz)

Cartesian Coordinates Vectors A vector represents a displacement A vector does not represent a location A vector does not have an origin or a destination A vector is created by the constructor vxyz def vx(dx): return vxyz(dx, 0, 0) def vy(dy): return vxyz(0, dy, 0) def vz(dz): return vxyz(0, 0, dz)

Cartesian Coordinates Vectors A vector represents a displacement A vector does not represent a location A vector does not have an origin or a destination A vector is created by the constructor vxyz xyz(x, y, z)+vxyz( x, y, z ) xyz(x + x, y + y, z + z )

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1))

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1)) xyz(2,5,8)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1)) xyz(2,5,8) > xyz(1,2,3) + xyz(4,5,6) - xyz(3,2,1)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1)) xyz(2,5,8) > xyz(1,2,3) + xyz(4,5,6) - xyz(3,2,1) RuntimeError: Positions cannot be added

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1)) xyz(2,5,8) > xyz(1,2,3) + xyz(4,5,6) - xyz(3,2,1) RuntimeError: Positions cannot be added > xyz(1,2,3) - xyz(3,2,1) + xyz(4,5,6)

Cartesian Coordinates Examples > xyz(1,2,3) + vxyz(3,2,1) xyz(4,4,4) > xyz(1,2,3) + vx(4) xyz(5,2,3) > xyz(1,2,3) + vyz(4,5) xyz(1,6,8) > xyz(1,2,3) - yz(1,1) vxyz(1,1,2) > vxy(1,2) + vxz(1,2) vxyz(2,2,2) > vxy(1,2) - vxz(1,2) vxyz(0,2,-2) > xyz(1,2,3) + (xyz(4,5,6) - xyz(3,2,1)) xyz(2,5,8) > xyz(1,2,3) + xyz(4,5,6) - xyz(3,2,1) RuntimeError: Positions cannot be added > xyz(1,2,3) - xyz(3,2,1) + xyz(4,5,6) xyz(2,5,8)

Polar Coordinates Y 2π n d. X

Polar Coordinates. ϕ ρ x y

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi))

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4) xyz(1.0000000000000002, 1.0, 0)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4) xyz(1.0000000000000002, 1.0, 0) > pol(1, pi/2)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4) xyz(1.0000000000000002, 1.0, 0) > pol(1, pi/2) xyz(6.123233995736766e-017, 1.0, 0)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4) xyz(1.0000000000000002, 1.0, 0) > pol(1, pi/2) xyz(6.123233995736766e-017, 1.0, 0) > pol(1, pi)

Polar Coordinates. ϕ ρ x y def pol(rho, phi): return xy(rho*cos(phi), rho*sin(phi)) > pol(1, 0) xyz(1, 0, 0) > pol(sqrt(2), pi/4) xyz(1.0000000000000002, 1.0, 0) > pol(1, pi/2) xyz(6.123233995736766e-017, 1.0, 0) > pol(1, pi) xyz(-1.0, 1.2246467991473532e-016, 0)

Polar Coordinates. ϕ ρ x y def vpol(rho, phi): return vxy(rho*cos(phi), rho*sin(phi)) > vpol(1, 0) vxyz(1, 0, 0) > vpol(sqrt(2), pi/4) vxyz(1.0000000000000002, 1.0, 0) > vpol(1, pi/2) vxyz(6.123233995736766e-017, 1.0, 0) > vpol(1, pi) vxyz(-1.0, 1.2246467991473532e-016, 0)

Polar Coordinates ρ P P ϕ.

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4)

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4) xyz(2.0, 3.0, 0.0)

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4) xyz(2.0, 3.0, 0.0) > xy(1, 2) + vpol(1, 0)

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4) xyz(2.0, 3.0, 0.0) > xy(1, 2) + vpol(1, 0) xyz(2.0, 2.0, 0.0)

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4) xyz(2.0, 3.0, 0.0) > xy(1, 2) + vpol(1, 0) xyz(2.0, 2.0, 0.0) > xy(1, 2) + vpol(1, pi/2)

Polar Coordinates ρ P P ϕ. > xy(1, 2) + vpol(sqrt(2), pi/4) xyz(2.0, 3.0, 0.0) > xy(1, 2) + vpol(1, 0) xyz(2.0, 2.0, 0.0) > xy(1, 2) + vpol(1, pi/2) xyz(1.0, 3.0, 0.0)

Geometric Modeling

Geometric Modeling For AutoCAD from khepri.autocad import *

Geometric Modeling For AutoCAD from khepri.autocad import * For Rhino from khepri.rhino import *

Geometric Modeling.

Geometric Modeling For AutoCAD from khepri.autocad import *. circle(pol(0, 0), 4) circle(pol(4, pi/4), 2) circle(pol(6, pi/4), 1)

Geometric Modeling For AutoCAD from khepri.autocad import *. circle(pol(0, 0), 4) circle(pol(4, pi/4), 2) circle(pol(6, pi/4), 1) For Rhino from khepri.rhino import * circle(pol(0, 0), 4) circle(pol(4, pi/4), 2) circle(pol(6, pi/4), 1)

Geometric Modeling polygon(pol(1, 2*pi*0/5), pol(1, 2*pi*1/5), pol(1, 2*pi*2/5), pol(1, 2*pi*3/5), pol(1, 2*pi*4/5))

Geometric Modeling polygon(pol(1, 2*pi*0/5), pol(1, 2*pi*1/5), pol(1, 2*pi*2/5), pol(1, 2*pi*3/5), pol(1, 2*pi*4/5)).

Geometric Modeling regular_polygon(5).

Geometric Modeling regular_polygon(3, xy(0, 0), 1, 0, True) regular_polygon(3, xy(0, 0), 1, pi/3, True) regular_polygon(4, xy(3, 0), 1, 0, True) regular_polygon(4, xy(3, 0), 1, pi/4, True) regular_polygon(5, xy(6, 0), 1, 0, True) regular_polygon(5, xy(6, 0), 1, pi/5, True)

Geometric Modeling regular_polygon(3, xy(0, 0), 1, 0, True) regular_polygon(3, xy(0, 0), 1, pi/3, True) regular_polygon(4, xy(3, 0), 1, 0, True) regular_polygon(4, xy(3, 0), 1, pi/4, True) regular_polygon(5, xy(6, 0), 1, 0, True) regular_polygon(5, xy(6, 0), 1, pi/5, True).

Geometric Modeling rectangle(xy(0, 1), xy(3, 2)) rectangle(xy(3, 2), 1, 2)

Geometric Modeling rectangle(xy(0, 1), xy(3, 2)) rectangle(xy(3, 2), 1, 2).

Side Effects rectangle(xy(0, 1), xy(3, 2)) rectangle(xy(3, 2), 1, 2).

Side Effects rectangle(xy(0, 1), xy(3, 2)) rectangle(xy(3, 2), 1, 2) Side Effects. Every Python expression has a value Some Python expressions also have a side effect All shape-producing expressions cause a side effect on the CAD tool Side effects can be composed by sequencing them A function that only does side effects returns nothing

Side Effects. P r P r

Side Effects. P r P r def circle_square(p, r, inscribed): if inscribed: creates a circle and a square inscribed in the circle else: creates a circle and a square circumscribed in the circle

Side Effects. P r P r def circle_square(p, r, inscribed): if inscribed: creates a circle creates a square inscribed in the circle else: creates a circle creates a square circumscribed in the circle

Side Effects. P r P r def circle_square(p, r, inscribed): if inscribed: circle(p, r) rectangle(p + vpol(r, 5/4*pi), p + vpol(r, 1/4*pi)) else: circle(p, r) rectangle(p + vxy(-r, -r), p + vxy(r, r))

Side Effects. P r P r def circle_square(p, r, inscribed): circle(p, r) if inscribed: rectangle(p + vpol(r, 5/4*pi), p + vpol(r, 1/4*pi)) else: rectangle(p + vxy(-r, -r), p + vxy(r, r))