Vectors, Points, Dot Product Coordinates, Transformations Lines, Edges, Intersections Triangles Circles
Vectors, Points, Dot Product Coordinates, Transformations Lines, Edges, Intersections Triangles Circles
Vectors,points,dotproduct
UpdatedSept2010
Coordinates,transformations
Lines,edges,intersections
Triangles
Circles
Coordinates:V=<V.x,V.y>
Opposite:V=<V.x,V.y>
Norm(orlength,ormagnitude):n(V)=(V.x2+V.y2)
Nullvector:=<0,0>,n()=0
Scaling:sV=<sV.x,sV.y>,V/s=<V.x/s,V.y/s>
Direction(unitvector):U(V)=V/n(V,assumen(V)0
Rotated90degrees:R(V)=<V.y,V.x>
Dotproduct(scalar):VU=U.xV.x+U.yV.y
Normsquared:V2=VV=(n(V))2
TangentialcomponentofVwrtU:VU=(VU)U/U2
AssumeV0,U0
Anglebetweentwovectors:cos(a)=VU/(n(V)*n(U))
Usedifferencebetweenpolarcoordinatestosortvectorsbyangle
VandUareorthogonal(i.e.perpendicular)whenVU=0
V.xU.x + V.yU.y = 0
VandUareparallelwhenVR(U)=0
V.xU.y = V.yU.x
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 8
Application:Motionprediction
Basedonlast4positions,howtopredictthenextone?
OPERATOROVERLOADINGFOR2DCONSTRUCTIONS
Whendealingwith2Dconstructions,wedefineUVasascalar:
UV=||U||||V||sin(angle(U,V))
The2Dcrossproductisthezcomponentofthe3Dcrossproduct.
Verifythatin2D:UV=UR(V)
Subtraction:PQ=QP=<Q.xP.x,Q.yP.y>
Translation(addvector):Q=P+V=(P.x+V.x,P.y+V.y)
Incorrectbutconvenientnotation:
Average:(P+Q)/2=((P.x+Q.x)/2,(P.y+Q.y)/2)
correct form: P+PQ/2
Weighted average:wiPi, with wi =1
correctform: O+wjOPj
P
P P
A A A
B C B
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 21
Edge intersection test
Linear parametric expression of the point P(s) on
edge(A,B)?
P(s) = A+sAB (also written (1s)A+sB ) for s in [0,1]
my Processing implementation is called L(A,s,B)
When do edge(A,B) and edge(C,D) intersect?
cw(A,B,C) != cw(A,B,D) ) && ( cw(C,D,A) !=
cw(C,D,B)
D
(special cases of collinear triplets require additional tests)
D
A B
C B
A
C
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 22
Normalprojectiononedge
WhendoestheprojectionQofpointPonltoLine(A,B)
fallbetweenAandB
i.e.:whendoesPprojectontoedge(A,B)?
when: P
0APABABAB A B
Q
orequivalently,when: P
0APAB&&0BPBA A B
Q
P
explainwhy:
A B
Q
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 23
PinE(point,edge):Pointinedgetest
WhenispointPinedge(a,b)?
when|abap|<||ab||&&abap>0&&babp>0
PROOF: p
q=projectionofpontotheline(a,b) a b
Thedistance||pq||fromptoqis q
|abap|/||ab|| p
Itneedstobelessthanathreshold a b
q
Wealsowanttheprojectionqtobe p
insideedge(a,b),hence: a b
abap>0&&babp>0 q
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 24
Parallellines
Whenareline(P,T)andline(Q,U)parallel
TU==0
orequivalentlywhen
TR(U)==0
Otherapproaches(solvelinearsystem):
S+tT==S+uTorQPN==0
QPN==0
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 27
Halfspace
LinearhalfspaceH(S,N)={P:SPN < 0 }
set of points P such that they are behind S with respect to N
N is the outward normal to the half-space
H(S,N) does not contain line {P:SPN==0 } (is topologically open)
L=line(S,T)(throughSwithtangentT)
L.right=H(S,R(T))
N=R(T) is the outward normal to the half-space
L.right is shown on the left in a Processing canvas (Y goes down)
L.right does not contain L (topologically open)
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 28
Transformations
Translation of P=(x,y) by vector V: TV(P) = P+V
Rotation : Ra(P) = ( x cos(a) y sin(a) , x sin(a) + y cos (a) )
by angle a around the origin
Composition: TV(Ra(P)), rotates by a, then translates by V
Translations commute: TU(TV(P))=TV(TU(P)) =TU+V(P)
2D rotations commute: Rb(Ra(P))=Ra(Rb(P))=Ra+b(P)
Rotations/translations do not commute: TV(Ra(P))Ra(TV(P))
Canonical representation of compositions of transformations:
Want to represent TW(Rc(TU(Rb(P)) as TV(Ra(P))
How to compute V and a?
How to apply it to points and vectors?
Answer: represent a composed transformation by a coordinate system
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 29
Coordinatesystem(frame)
Coordinatesystem[I,J,O]
O is the origin of the coordinate system (a translation vector)
{I,J} is an ortho-normal basis: I.norm=1, J=R(I)
{I,J} captures the rotation part of the transformation
Given local coordinates (x,y) of P in [I,J,O]
P=O+xI+yJ, start at O, move by x along I, move by y along J
Given P, O, I, J, compute (x,y)
x=OPI, y=OPJ
proof: OPI=xII+yJI=xII
ThiscanbeexecutedinProcessing(andOpenGL)as3transforms:
TranslatebyCO(nowCisattheoriginandPisatO+CP)
Rotatebyanglea(rotatesCParoundorigin:O+CP.rotate(a))
TranslatebyOC(toputthingsback:O+CP.rotate(a)+OC)
(
What is the matrix form of this rotation?
cos(a) P.x sin(a) P.y
sin(a) P.x + cos(a) P.y
cos(a)
sin(a)
sin(a)
cos(a)
)(
= )( )
P.x
P.y
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 33
Change of frame
Let (x1,y1) be the coordinates of P in [I1 J1 O1]
Applications:
WhatdothecolumnsofMrepresent?
AcanonicaltransformationTO(Ra(P))
O = <O.x,O.y> is the translation vector
[I,J] is the local basis (image of the global basis)
(I J) is a 22 rotation matrix: I.x = J.y = cos(a), I.y = J.x = sin(a)
a = atan2(I.y,I.x) is the rotation angle, with a[,]
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 35
Homogeneousmatrices
Representa2Dcoordinatesystembya33homogeneousmatrix
Transformpointsandvectorsthroughmatrixvectormultiplication
ForpointPwithlocalcoordinate(x,y)use<x,y,1>
ForvectorVwithlocalcoordinate<x,y>,use<x,y,0>
ComputingtheglobalcoordinatesofPfromlocal(x,y)ones
<P.x,P.y,1> = [I.h J.h O.h](x,y,1) = xI.h + yJ.h + O.h.
Vectorsarenotaffectedbyorigin(notranslation)
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 36
Invertingahomogeneousmatrix
The inverse of Ra is Ra
The inverse of a rotation matrix is its transpose
I.x = J.y = cos(a) remain unchanged since cos(a) = cos(a)
I.y = J.x = sin(a) change sign (swap places) since sin(a) = sin(a)
The inverse of TV is TV
The inverse of TV(Ra(P)) is Ra(TV(P))
It may also be computed directly as x=OPI, y=OPJ
QPN=0,thevectorfromQtoapointonthelineisorthogonaltoN
P(t)=S+tV,thedisplacementistime*velocity
QP(t)=P(t)Q=S+tVQ=(SQ)+tV=QS+tV
(QS+tV)N=0,conditionforP(t)tobeontheline
Solvingfortbydistributingover+
t=(SQN)/(VN),noticethatSQ=QS
WhenVN=0:nocollision
Qmayalreadybeontheline
Computet=(SQN)/(VN),asinthepreviousslideand
substitutethisexpressionfortinP=S+tV,yielding:
P=S+((SQN)/(VN))V
IfVN=0:nointersection
Since|V|=1,P(t)hastraveledadistanceoftfromS.
ThedistancebetweenP(t)andthelinethroughQwithnormalNisQP(t) N
Hence,wehavetwoequations:P(t)=S+tVandQP(t) N=t
Solvefortbysubstitution:t=(QSN)/(1VN)
IfVN=0,useNinsteadofN
d=QPN,asusedinthepreviousquestion
Fromquestion5:
r=(QSN)/(1VN)
WhenVN=0,useN
G=S+rV
A B
Linethrough(A+B)/2
WithnormalN=AB.left.unit
A S B
V
WecomputethebisectorsofABandBC t
Q C
andusetheresultofquestion3
S=(A+B)/2;V=BA.left.unit G
Q=(B+C)/2;N=BC.unit N
t=(SQN)/(VN)(fromquestion3)
G=S+tV
r=GB.unit
Jarek Rossignac, 2010 www.gvu.gatech.edu/~jare 55
10)Distance
WhatisthesquaredistancebetweenpointsPandQ
PQPQ
Similarlytoquestiont,wehaveP(t)=S+tV
andwanttsuchthat(QP(t))2=t2
usingW2isWW
(QS+tV)(QS+tV)=t2
DistributingandusingVV=1permitstoeliminatet2
Solvingfort:
t=QS2/(2QSV)
A C
AC.unit
N
B
BA BC
A V V C
D
Velocity:V=AC/2
BC
DN
Normal:N=V.left.unit
Acceleration:D=BA+BC
Normalacceleration:DN G
r=V2/D N
Thecenteroftheosculatingcircle
G=BrN
B
N
A C
V
V:= AC/2 ;
N:= BA + ((ABV)/(VV))
V;
G:= B + ((VV)/(2NN)) N ;
|PC(T.left)| r
CP = PC = PStT = SPtT
(SPtT)( SPtT) = r2
(SPSP)2(SPT)t+(TT)t2 = r2 (distribute over )
t22(SPT)t+(SP2r2)=0
Solve for t: real roots, t1 and t2, assume t1<t2
Points S+tT when t]t1,t2[ are in Disk(C,r)