51
CMSC427 Geometry and Vectors

CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

CMSC427GeometryandVectors

Page 2: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• ParametriccurvesandHw1?• Goingbeyondthecourse:generativeart• https://www.openprocessing.org• BrandonMorse,ArtDept,ART370

• Polylines,ProcessingandLab0?• QuestionsonProcessing?• https://processing.org• LearningProcessing– DanShiffman

Review: where are we?

Page 3: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Findalineperpendiculartoanother?

• Findsymmetricreflectingvectoronamirror?

• Findthedistancefromapointtoaline?

• Figureoutifafacetisfacingthecamera?

How can we …

Page 4: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Polyline and points

P0

P1

P2

P3

P4

P5

• Polylineassequenceoflocations(points)

Page 5: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Polyline and vectors

• Polylineaspointplussequenceofvectors• Assumption:displacements<<locations,fewerbits

P0

V1

V2

V3

V4

V5

Page 6: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Polyline as vectors

• Polylineaspointplussequenceofvectors• Assumption:displacements<<locations,fewerbits

P0

V1

V2

V3

V4

V5

P1=P0+V1P2=P1+V1=P0+V1+V2

Page 7: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector and vector operations

• Objects:• Points(x,y)– representposition• Vector<x,y>– representdisplacement,direction

• Operations:• Vectoraddition,subtraction,scaling• Vectormagnitude• Vectordotproduct• Vectorcrossproduct• Linear,affineandconvexcombinations

• Applications:• Representations:usingvectorsforlines,planes,others• Metrics:anglebetweenlines,distancesbetweenobjects• Tests:aretwolinesperpendicular,isafacetvisible?

Page 8: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Directionanddistance• Describes• Differencebetweenpoints• Speed,translation,axes

• Notation• Inbolda• Anglebracketsa =<x,y>

• Freevectors• Noanchorpoint• Displacement,notlocation

Vectors

a

a P0

P1

a =P1-P0

Page 9: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector scaling

Multiplicationbyscalar sa

a 0.5a -1a = -a

Page 10: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector addition and subtraction

a b

ba

c = a + b

-b

ac = a - b

Page 11: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector addition and subtraction

a

b

c

Whatisc intermsofa andb?

Page 12: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector addition and subtraction

a

b

c

Whatisc intermsofa andb?

a +c=b

Page 13: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector addition and subtraction

a

b

c

Whatisc intermsofa andb?

a +c =b

a

b

c = b - a

Page 14: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Coordinate vs. coordinate-free representation

Coordinate-freeequationValidfor2Dand3D

Preferwhenpossible

Coordinateequationa=<3,3>b =<4,2>

c=b- a=<4,2>- <3,3>=<1,-1>

a

b

c = b - a

Page 15: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Parametric line in coordinate-free vector format

t = 0

t = 0.25

t = 0.75

t = 1

t = 0.5

𝑥 = 𝑡𝑑𝑥 + 𝑝𝑥𝑦 = 𝑡𝑑𝑦 + 𝑝𝑦

𝑃0

𝑃1

Set𝑽 = 𝑃1 − 𝑃0=< 𝑑𝑥, 𝑑𝑦 >

Then𝑃(𝑡) = 𝑡𝑽 + 𝑃0

Goodin2Dand3D

Page 16: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Vector magnitude

Themagnitude(length)ofavectoris

v 4 = 𝑣64 + 𝑣74

v = 𝑣64 + 𝑣74�

Avectoroflength1.0iscalledaunitvector

Tonormalize avectoristorescaleittounitlength

n: =vv

Normalvectorsrepresentdirectionandareusedfor:lightdirection,surfacenormals,rotationaxes

Page 17: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Innerproductbetweentwovectors• Definedusingcoordinate-freecosinerule

Dot product

𝐚•b = a b cos(𝜃)

b

Page 18: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Innerproductbetweentwovectors• Definedusingcoordinate-freecosinerule

• Example:

Dot product

𝐚•b = a b cos(𝜃)

b

𝐚 =< 1,1 >𝐛 =< 1,0 >𝜃 = π/2

𝐚•b = 1.4142 ∗ 1 ∗ 0.70711 = 1b

a

θ=π/2

Page 19: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Given

• Then

• Inndimensions

Dot product – coordinate version

𝐚•b = 𝒂𝒙𝒃𝒙 + 𝒂𝒚𝒃𝒚

𝐚 = 𝒂𝒙, 𝒂𝒚 𝐛 = 𝒃𝒙, 𝒃𝒚

𝐚•b =O𝒂𝒊𝒃𝒊

𝒏

𝒊R𝟏

Page 20: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Given

• Then

• Examplerevised:

Dot product – coordinate version

𝐚•b = 𝒂𝒙𝒃𝒙 + 𝒂𝒚𝒃𝒚

𝐚 = 𝒂𝒙, 𝒂𝒚 𝐛 = 𝒃𝒙, 𝒃𝒚

𝐚 =< 1,1 >𝐛 =< 1,0 >

𝐚•b = 1 ∗ 1 + 1 ∗ 0 = 1b

a

θ=π/2

Page 21: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Given• Wehave

• Example

Dot product: computing angle (and cosine)

𝐚•b = a b cos(𝜃)

cos 𝜃 =𝐚•ba b

𝜃 = cosT𝟏𝐚•ba b

𝐚 =< 1,1 >, 𝐛 =< 1,0 >𝐚•b = 1 ∗ 1 + 1 ∗ 0 = 1a = 𝟏. 𝟒𝟏𝟒𝟐, b = 𝟏. 𝟎

𝐚•ba b =

𝟏𝟏. 𝟒𝟏𝟒𝟐 = 𝟎. 𝟕𝟎𝟕𝟏𝟏

cosT𝟏𝐚•ba b = 𝟎. 𝟕𝟖𝟓𝟒𝟎 =𝝅/𝟒 b

a

θ=π/4

Page 22: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Since

• Thenaperpendiculartobgives

• Examples

Dot product: testing perpendicularity

𝐚 ⊥ b ⇒ 𝐚 • b = 0

cos 90° = cos𝜋2 = 𝟎

𝐚 =< 1,0 >, 𝐛 =< 0,1 >𝐚•b = 1 ∗ 0 + 1 ∗ 0 = 0

𝐚 =< 1,1 >, 𝐛 =< −1,1 >𝐚•b = 1 ∗ −1 + 1 ∗ 1 = 0

Page 23: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Givenvector

• Theperpvectoris

• So

Perp vector and lines

=< −𝑣7, 𝑣6 >

𝐯 =< 𝑣6, 𝑣7 >

𝐯•𝐯b = 0

Page 24: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• GivenlinesegmentP0toP1,whatlineisperpendicularthroughthemidpoint?

Midpoint bisector

P0 = (1,1)

P1= (5,3)

Page 25: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• GivenlinesegmentP0toP1,whatlineisperpendicularthroughthemidpoint?

Midpoint bisector

v = P1-P0

P0 = (1,1)

P1= (5,3)

n = v_perp/|v_perp|

m = (P0+P1)/2

Page 26: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Result:bisectoris

• Withnnormalizedperpvector,mmidpoint• Appropriaterangeoft?

Midpoint bisector

v = P1-P0

P0 = (1,1)

P1= (5,3)

n = v_perp/|v_perp|

P = t n + m

m = (P0+P1)/2

𝑃 = 𝑡n +𝑚

Page 27: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Midpoint displacement terrain (2D recursive algorithm)

• GiventwopointsP0,P1• Computemidpointm• ComputebisectorlineP=tn +m• Pickrandomt,generateP’• CallrecursivelyonsegmentsP0-P’,P’-P1

• Tuningneededonmagnitudeofdisplacement

Page 28: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Midpoint displacement terrain (3D recursive algorithm)

• StartwithfourpointsP0,P1,P2,P3• Divide(quadsortriangles?)• Computemidpointbisector(how?)• Displace,repeat

HunterLoftis

P0 P1

P2P3

Page 29: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Readas“acrossb”• axbisavectorperpendiculartobothaandb,inthedirectiondefinedbytherighthandrule

Cross product

a×b

Page 30: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Readas“acrossb”• axbisavectorperpendiculartobothaandb,inthedirectiondefinedbytherighthandrule• Vectoraandblieintheplaneoftheprojectionscreen.• Doesaxbpointtowardsyouorawayfromyou?

Whataboutb xa?

Cross product

a×b

b

a

Page 31: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• HowcomputenormalvectortotriangleP0,P1,P3?• Assumeupisoutofpage

Cross product: normal to plane

P0 P1

P2P3

Page 32: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• HowcomputenormalvectortotriangleP0,P1,P3?• Assumeupisoutofpage

• Oneanswer:n=(P1-P3)x(P0-P1)

Cross product: normal to plane

P0 P1

P2P3

Page 33: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Parallelogramrule

• Areaofmeshtriangle?• Whenwouldcrossproductbezero?

Cross product: length of a x b

𝐚×b = a b sin(𝜃)

𝐚×b = 0

Page 34: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Parallelogramrule

• Areaofmeshtriangle?• Whenwouldcrossproductbezero?

• Eithera,b parallel,oreitherdegenerate

Cross product: length of a x b

𝐚×b = a b sin(𝜃)

𝐚×b = 0

Page 35: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Cross product: computing, vector approach

𝐚×b =𝑎7𝑏h − 𝑎h𝑏7𝑎h𝑏6 − 𝑎6𝑏h𝑎6𝑏7 − 𝑎7𝑏6

Page 36: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

• Determinantof

• Computedwith3lowerminors

• with

• i,j,kareunitvectorsindirectionsofx,yandzaxes• i=<1,0,0> j=<0,1,0> k=<0,0,1>

Cross product: computing, matrix approach

𝐚×b =𝑖 𝑗 𝑘𝑎6 𝑎7 𝑎h𝑏6 𝑏7 𝑏h

𝐚×b = 𝑖𝑎7 𝑎h𝑏7 𝑏h − 𝑗

𝑎6 𝑎h𝑏6 𝑏h + 𝑘

𝑎6 𝑎7𝑏6 𝑏7

𝑎 𝑏𝑐 𝑑 = 𝑎𝑑 − 𝑐𝑏

Page 37: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Midpoint of triangle?

P0

P1

P2?

Page 38: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Midpoint of triangle?

P0

P1

P2?

Answer1:

𝑚 =𝑃0 + 𝑃1 + 𝑃2

3

Page 39: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Midpoint of triangle?

Answer2:Doubleinterpolation(blending)

Firstinterpolation:vectorlineP0toP1

Midpointatt=0.5

𝑃 = 𝑡𝑉 + 𝑃0

P0

P1

P2

m0= 𝑡(𝑃1 − 𝑃0) + 𝑃0= 𝑡𝑃1 + (1 − 𝑡)𝑃0

𝑚0 = 0.5𝑃1 + (1 − 0.5)𝑃0= 0.5𝑃1 + 0.5𝑃0

=𝑃1 + 𝑃0

2

Page 40: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

P0

P1

P2

m0

m

Midpoint of triangle?

Answer2:Doubleinterpolation

Secondinterpolation:vectorlinem0toP2

Midpointats=1/3

𝑃 = 𝑠𝑉′ + 𝑚0= 𝑠(𝑃2 −𝑚0) +𝑚0= 𝑠𝑃2 + 1 − 𝑠 𝑚0

𝑚0 =13𝑃2 + 1 −

13 𝑚0

=13𝑃2 +

23𝑚0 =

𝑃2 + 𝑃1 + 𝑃03

=13𝑃2 +

23 (0.5𝑃1 + 0.5𝑃0)

Page 41: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Generalizing: convex combinations of points

AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1

withand𝐶 = O 𝛼t𝑃t

utvw

O𝛼t = 1�

0 ≤ 𝛼t ≤ 1

Page 42: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Generalizing: convex combinations of points

AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1

withand

Isthisequationforalinesegment aconvexcombination?

𝐶 = O 𝛼t𝑃t

utvw

𝑃 = 𝑡𝑃1 + (1 − 𝑡)𝑃0

O𝛼t = 1�

0 ≤ 𝛼t ≤ 1

Page 43: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Generalizing: convex combinations of points

AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1

withand

Isthisequationforalinesegment aconvexcombination?

Yes.Withtin[0,1],tand(1-t)>=0,andt+(1-t)=1

𝐶 = O 𝛼t𝑃t

utvw

𝑃 = 𝑡𝑃1 + (1 − 𝑡)𝑃0

O𝛼t = 1�

0 ≤ 𝛼t ≤ 1

Page 44: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Generalizing: convex combinations of points

AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1

withand

Isthisequationforatriangleaconvexcombination,assumingsandtarein[0,1]?

𝐶 = O 𝛼t𝑃t

utvw

𝑃 = 𝑠𝑃2 + (1 − 𝑠)(𝑡𝑃1 + 1 − 𝑡 𝑃0)

O𝛼t = 1�

= 𝑠𝑃2 + (1 − 𝑠)(𝑡𝑃1) + (1 − 𝑠) 1 − 𝑡 𝑃0)= 𝑠𝑃2 + (𝑡 − 𝑠𝑡)𝑃1 + (1 − 𝑠 − 𝑡 + 𝑠𝑡)𝑃0

0 ≤ 𝛼t ≤ 1

Page 45: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Generalizing: convex combinations of points

AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1

withand

Forgeneralpolygon,allconvexcombinationsofverticesyieldsconvexhull

𝐶 = O 𝛼t𝑃t

utvw

O𝛼t = 1�

0 ≤ 𝛼t ≤ 1

Page 46: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Linear, affine and convex combinations

Linear: Noconstraintsoncoefficients

Affine: Coefficientssumto1

with

Convex: Coefficientssumto1,eachin[0,1]

withand

𝐶 = O 𝛼t𝑃t

utvw

O𝛼t = 1�

0 ≤ 𝛼t ≤ 1

𝐶 = O 𝛼t𝑃t

utvw

𝐶 = O 𝛼t𝑃t

utvw

O𝛼t = 1�

Page 47: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Linear combinations of points vs. vectors

Point– pointyieldsa….

Vector– vectoryieldsa…

Point+vectoryieldsa…

Point+pointyieldsa…

Page 48: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Linear combinations of points vs. vectors

Point– pointyieldsa….vector

Vector– vectoryieldsa… vector

Point+vectoryieldsa… point

Point+pointyieldsa… ????Notdefined

VectorsareclosedunderadditionandsubtractionAnylinearcombinationvalid

PointsarenotAffinecombinationthatsumsto0yieldsvectorAffinecombinationthatsumsto1yieldspointConvexcombinationyieldspointinconvexhull

Moral:Whenprogrammingw/pts&vtrs,knowtheoutputtype

Page 49: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

Applying vectors operations to polygons

Isapolygonwindingclockwise?

Isapolygonconvex?

Isapolygonsimple?

Lab1:addthesemethodstoPolylineclass

Page 50: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

1. Normalformofline2. Normalformofplane3. Programmingwithpointsandvectors4. Signofdotproduct5. Tweening6. Distancefrompointtoline

If time allows …

Page 51: CMSC427 Geometry and Vectorsreastman/slides/L03P1Vectors.pdf · 2. Vector math: scaling, addition, subtraction 3. Coordinate and coordinate-free formulas 4. Vector magnitude and normalization

1. Notationforvectors<x,y>andpts(x,y)2. Vectormath:scaling,addition,subtraction3. Coordinateandcoordinate-freeformulas4. Vectormagnitudeandnormalization5. Dotproductsandcosinerule6. UsingOctaveOnlineasvectorcalculator7. Dotproduct,perpendicularityandperpvector8. Midpointbisector9. Midpointdisplacementalgorithm10. Crossproduct,righthandruleandsinerule11. Computingcrossproductwithdeterminant12. Linear,affineandconvexcombinations13. Trianglemidpoint

What you should know after today