Вы находитесь на странице: 1из 2

A Computational Geometry briefcase:

Vectors:
Dot Product: A.B=Ax.Bx + Ay.By + Az.Bz (Scalar) = (Magnitude of A) x (Magnitude of B) x cos (angle bet een A!B) = ("o#$onent of A || to B) x (Magnitude of B) "ross Product: AxB = deter#inant of %i & '% (deter#inant = su# t(e $roduct ()ector) %Ax Ay Az % of t(e *+, diagonals - su# %Bx By Bz % $roduct of t(e *., diagonals) = area of t(e %%gra# of A and B/ $ointing in a direction 01o to bot( A and B/ suc( t(at if AxB ere $ointing to ard you and A ere $ointing u$/ t(en B ould $oint to t(e rig(t. (for 2D let Az/ Bz=1)

Useful formulae/facts
3. 4or 2 2D 5ectors A/ B: Ax. By 6 Ay. Bx is $ositi5e if t(e cloc' ise angle bet een A and B is acute or obtuse/ 1 if it is 371 and negati5e if it is reflex8 2. A %% B <=> AxB=18 9. A |: B <=> A.B =18 ;. area of AB" = < %(A6B)x(A6C)%8 =. 4or line seg#ents AB and "D to intersect in 2D8 A/B #ust be on different sides of "D and 5isa65ersa8 >. 4or line seg#ents AB and "D to intersect in 9D8 A/B #ust be on different sides of "D and 5isa65ersa/ and AB"D #ust be co$lanar ?. to find t(e $oint of intersection (if it exists)/ Sol5e: Ax + (Bx6Ax) i ="x+ (Dx6"x) & Ay + (By6Ay) i ="y+ (Dy6"y) & Az + (Bz6Az) i ="z+ (Dz6"z) & (in t(e case of 9d 5ectors) @f 1Ai/&A3/ t(en t(e $oint is (Ax +(Bx6Ax)i8Ay +(By6Ay)i8Az +(Bz6Az)i)8 7. Distance fro# P to line A/B: %(A-P)x(A-B)|/|A-B|; 0. Distance fro# P to $lane A/B/": %((A-B)x(A-C)).(P-A)|/ |(A-B)x(A-C)|; 31. @f a $oint P is on a line8 its distance to t(e line is 1/ if it is on a line seg#ent AB/ it is on t(e line and AP+PB=AB8 33. if a $oint P is on a $lane AB"/ t(en its distance to t(e $lane is 1 (note u can dro$ t(e *.|(A-B)x(A-C)|,as t(is ont c(ange (et(er distance = 1)8 32. to test if a $oint is in a triangle test t(at it is on t(e sa#e side of eac( line as t(e centre of gra5ity (t(is or's for con5ex $olygons as ell)8 39. to test if a $oint P is in a conca5e $olygon test t(e nu#ber of ti#es a rando# ray generated fro# P crosses t(e $olygon sides (e5en =B outside/ odd=B inside)/ note if ray $asses t(roug( any 5ertices t(en a ne ray #ust be $ic'ed8 3;. to test if a $olygon is con5ex (in 2D)/ ta'e e5ery 9 consecuti5e edges (a/b/c) and c(ec' t(at (b6a)x(c6b) (as t(e sa#e sign for e5ery 9 $oints8 3=. to find a closest $air of $oints out of a set8 sort t(e# by x co6ordinates/ t(en recursi5ely s$lit t(e grou$ into 2/ ta'e t(e #in(#in left grou$/ #in rig(t grou$/ #in cross grou$s).(note t(at for t(e cross grou$s/ u only need to loo' at $oints it(in #in(#in left grou$/ #in rig(t grou$)or t(e #iddle line)8

3>. Algorit(# for generating a si#$le closed $at(: select t(e left #ost of t(e botto# #ost $oints/ sort t(e ot(er $oints according to t(e angle t(ey #a'e (en &oined it( t(e anc(or. Put anc(or in front of list: 3?. Algorit( for generating t(e con5ex (ull: generate si#$le closed $at(/ loo$ round t(e $at(/ if t(e $resent 5ertex is con5ex (use $oint 3) #o5e to t(e next 5ertex/ if not re#o5e t(e 5ertex and #o5e to t(e $re5ious 5ertex.

Other things worth being mentioned:


Colerances: ne5er test for eDuality it( floating $oint nu#bers/ al ays test is t(e t o $oints are it(in a certain error #argin of eac( ot(er. S$ecial cases: co#$utational geo#etry is full of s$ecial cases/ #a'e sure your $rogra# sol5es t(e# Partitioning: di5iding t(e $lane.s$ace into different areaEs so as to a5oid (a5ing to c(ec' t(roug( all $oints.lines etc. Monte "arlo: instead of calculating t(e $robability of so#et(ing (a$$ening/ generate #any rando# e5ents and test (et(er t(ey fulfil t(is $ro$erty (eg/ (en trying to calculate t(e area of a s(a$e/ $ut it in a box/ generate rando# $oints in t(e box/ and test (o #any are in t(e s(a$e: area of s(a$e = (area of box) x (nu#ber of $oints in s(a$e). nu#ber or $oints.)

Вам также может понравиться