• ParametriccurvesandHw1?• Goingbeyondthecourse:generativeart• https://www.openprocessing.org• BrandonMorse,ArtDept,ART370
• Polylines,ProcessingandLab0?• QuestionsonProcessing?• https://processing.org• LearningProcessing– DanShiffman
Review: where are we?
• Findalineperpendiculartoanother?
• Findsymmetricreflectingvectoronamirror?
• Findthedistancefromapointtoaline?
• Figureoutifafacetisfacingthecamera?
How can we …
Polyline and vectors
• Polylineaspointplussequenceofvectors• Assumption:displacements<<locations,fewerbits
P0
V1
V2
V3
V4
V5
Polyline as vectors
• Polylineaspointplussequenceofvectors• Assumption:displacements<<locations,fewerbits
P0
V1
V2
V3
V4
V5
P1=P0+V1P2=P1+V1=P0+V1+V2
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?
• Directionanddistance• Describes• Differencebetweenpoints• Speed,translation,axes
• Notation• Inbolda• Anglebracketsa =<x,y>
• Freevectors• Noanchorpoint• Displacement,notlocation
Vectors
a
a P0
P1
a =P1-P0
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
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
Vector magnitude
Themagnitude(length)ofavectoris
v 4 = 𝑣64 + 𝑣74
v = 𝑣64 + 𝑣74�
Avectoroflength1.0iscalledaunitvector
Tonormalize avectoristorescaleittounitlength
n: =vv
Normalvectorsrepresentdirectionandareusedfor:lightdirection,surfacenormals,rotationaxes
• Innerproductbetweentwovectors• Definedusingcoordinate-freecosinerule
Dot product
𝐚•b = a b cos(𝜃)
b
aθ
• Innerproductbetweentwovectors• Definedusingcoordinate-freecosinerule
• Example:
Dot product
𝐚•b = a b cos(𝜃)
b
aθ
𝐚 =< 1,1 >𝐛 =< 1,0 >𝜃 = π/2
𝐚•b = 1.4142 ∗ 1 ∗ 0.70711 = 1b
a
θ=π/2
• Given
• Then
• Inndimensions
Dot product – coordinate version
𝐚•b = 𝒂𝒙𝒃𝒙 + 𝒂𝒚𝒃𝒚
𝐚 = 𝒂𝒙, 𝒂𝒚 𝐛 = 𝒃𝒙, 𝒃𝒚
𝐚•b =O𝒂𝒊𝒃𝒊
𝒏
𝒊R𝟏
• Given
• Then
• Examplerevised:
Dot product – coordinate version
𝐚•b = 𝒂𝒙𝒃𝒙 + 𝒂𝒚𝒃𝒚
𝐚 = 𝒂𝒙, 𝒂𝒚 𝐛 = 𝒃𝒙, 𝒃𝒚
𝐚 =< 1,1 >𝐛 =< 1,0 >
𝐚•b = 1 ∗ 1 + 1 ∗ 0 = 1b
a
θ=π/2
• 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
• 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
• GivenlinesegmentP0toP1,whatlineisperpendicularthroughthemidpoint?
Midpoint bisector
P0 = (1,1)
P1= (5,3)
• GivenlinesegmentP0toP1,whatlineisperpendicularthroughthemidpoint?
Midpoint bisector
v = P1-P0
P0 = (1,1)
P1= (5,3)
n = v_perp/|v_perp|
m = (P0+P1)/2
• 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 +𝑚
Midpoint displacement terrain (2D recursive algorithm)
• GiventwopointsP0,P1• Computemidpointm• ComputebisectorlineP=tn +m• Pickrandomt,generateP’• CallrecursivelyonsegmentsP0-P’,P’-P1
• Tuningneededonmagnitudeofdisplacement
Midpoint displacement terrain (3D recursive algorithm)
• StartwithfourpointsP0,P1,P2,P3• Divide(quadsortriangles?)• Computemidpointbisector(how?)• Displace,repeat
HunterLoftis
P0 P1
P2P3
• Readas“acrossb”• axbisavectorperpendiculartobothaandb,inthedirectiondefinedbytherighthandrule
Cross product
a×b
• Readas“acrossb”• axbisavectorperpendiculartobothaandb,inthedirectiondefinedbytherighthandrule• Vectoraandblieintheplaneoftheprojectionscreen.• Doesaxbpointtowardsyouorawayfromyou?
Whataboutb xa?
Cross product
a×b
b
a
• HowcomputenormalvectortotriangleP0,P1,P3?• Assumeupisoutofpage
Cross product: normal to plane
P0 P1
P2P3
• HowcomputenormalvectortotriangleP0,P1,P3?• Assumeupisoutofpage
• Oneanswer:n=(P1-P3)x(P0-P1)
Cross product: normal to plane
P0 P1
P2P3
• Parallelogramrule
• Areaofmeshtriangle?• Whenwouldcrossproductbezero?
Cross product: length of a x b
𝐚×b = a b sin(𝜃)
𝐚×b = 0
• Parallelogramrule
• Areaofmeshtriangle?• Whenwouldcrossproductbezero?
• Eithera,b parallel,oreitherdegenerate
Cross product: length of a x b
𝐚×b = a b sin(𝜃)
𝐚×b = 0
• 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
𝑎 𝑏𝑐 𝑑 = 𝑎𝑑 − 𝑐𝑏
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
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)
Generalizing: convex combinations of points
AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1
withand𝐶 = O 𝛼t𝑃t
�
utvw
O𝛼t = 1�
0 ≤ 𝛼t ≤ 1
Generalizing: convex combinations of points
AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1
withand
Isthisequationforalinesegment aconvexcombination?
𝐶 = O 𝛼t𝑃t
�
utvw
𝑃 = 𝑡𝑃1 + (1 − 𝑡)𝑃0
O𝛼t = 1�
0 ≤ 𝛼t ≤ 1
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
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
Generalizing: convex combinations of points
AconvexcombinationofasetofpointsSisalinearcombinationsuchthatthenon-negativecoefficientssumto1
withand
Forgeneralpolygon,allconvexcombinationsofverticesyieldsconvexhull
𝐶 = O 𝛼t𝑃t
�
utvw
O𝛼t = 1�
0 ≤ 𝛼t ≤ 1
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�
Linear combinations of points vs. vectors
Point– pointyieldsa….
Vector– vectoryieldsa…
Point+vectoryieldsa…
Point+pointyieldsa…
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
Applying vectors operations to polygons
Isapolygonwindingclockwise?
Isapolygonconvex?
Isapolygonsimple?
Lab1:addthesemethodstoPolylineclass
1. Normalformofline2. Normalformofplane3. Programmingwithpointsandvectors4. Signofdotproduct5. Tweening6. Distancefrompointtoline
If time allows …
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
Top Related