elements of 2d computational geometrytschwarz/coen129/ppt/analyticalgeometry.pdf · elements of 2d...

Post on 06-Aug-2018

229 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Elements of 2d Computational Geometry

AI for Gaming Santa Clara, 2016

3d Determinants

Absolute value is the volume of the parallelepiped Sign is the orientation

2d Orientation

A B

CA+B

A+C B+CA+B+C

Sign of determinant

������

ax

ay

1

bx

by

1

cx

cy

1

������

depends on the orientation of the points (ax

, ay

, 1), (bx

, by

, 1) and (cx

, cy

, 1).If (a

x

, ay

), (bx

, by

), and (cx

, cy

) are oriented counterclockwise, then and only

then is the determinant positive.

Application

A

BC

D

Do two lines intersect?

C lies on a di↵erent side of AB than DSigns of determinants are di↵erent

������

ax

ay

1

bx

by

1

cx

cy

1

������⇥

������

ax

ay

1

bx

by

1

dx

dy

1

������< 0.

2d Circles• Three points determine a circle

• If they are collinear, the circle is degenerate • with a radius of infinity

A B

C

2d Circles• Geometric construction:

• Draw two chords AB and BC

A B

C

2d Circles• Given three points A, B, C • Draw cords AB, BC • Create perpendicular

bisectors for each chord • By drawing a large enough circle

around A and B • The intersection is the center

of the circle • Radius is the distance of

center point to one of the three points

A B

C

2d Circles• Determine whether a point is inside a circle

• If the circle is given by center and radius • Calculate distance of point from center and

compare with radius • If the circle is given by three points

• Use determinant formula • No need to calculate circle first

2d Circles• Calculate the following determinant

• If A, B, C are in counter-clockwise order and the determinant is positive, then D lies inside the circle

• If A, B, C are in counter-clockwise order and the determinant is negative, then D lies not inside the circle

• If A, B, C are not in counter-clockwise order and the determinant is negative, then D lies inside the circle

• If A, B, C are not in counter-clockwise order and the determinant is positive, then D lies not inside the circle

��������

ax

ay

a2x

+ a2y

1bx

by

b2x

+ b2y

1cx

cy

c2x

+ c2y

1dx

dy

d2x

+ d2y

1

��������=

������

ax

� dx

ay

� dy

(ax

� dx

)2 + (ay

� dy

)2

bx

� dx

by

� dy

(bx

� dx

)2 + (by

� dy

)2

cx

� dx

cy

� dy

(cx

� dx

)2 + (cy

� dy

)2

������

Barycentric Coordinates• Given three (not collinear)

points a, b, c • Every point p can be written

as • p=αa+βb+(1-α-β)c• Divides plane into seven

areas depending on the signs of the coefficients

Α

Β

C

P

-+-

++-

+--

+++

--+

-++ +-+

~p = ↵~a+ �~b+ (1� ↵� �)~c

, ~p� ~c = ↵(~a� ~c) + �(~b� ~c)

which implies

(~p� ~c) · (~a� ~c) = ↵(~a� ~c) · (~a� ~c) + �(~b� ~c) · (~a� ~c)

(~p� ~c) · (~b� ~c) = ↵(~a� ~c) · (~b� ~c) + �(~b� ~c) · (~b� ~c)

which gives according to Cramer’s rule

↵ =

�����(~p� ~c) · (~a� ~c) (

~b� ~c) · (~a� ~c)

(~p� ~c) · (~b� ~c) (

~b� ~c) · (~b� ~c)

����������(~a� ~c) · (~a� ~c) (

~b� ~c) · (~a� ~c)

(~a� ~c) · (~b� ~c) (

~b� ~c) · (~b� ~c)

�����

� =

����(~a� ~c) · (~a� ~c) (~p� ~c) · (~a� ~c)

(~a� ~c) · (~b� ~c) (~p� ~c) · (~b� ~c)

���������(~a� ~c) · (~a� ~c) (

~b� ~c) · (~a� ~c)

(~a� ~c) · (~b� ~c) (

~b� ~c) · (~b� ~c)

�����

Barycentric Coordinates• We note that in the preceding formula

• Only two dot products change if we change point p

Lines, Rays, Segments• Lines

• Given by two points a and d

a

dL={(1-t)a+td | t real}

Lines, Rays, Segments• Ray given by two points

a

dL={(1-t)a+td | t >= 0}

Lines, Rays, Segments• Segment between two points

a

dL={(1-t)a+td | 0 <= t <= 1}

Dot Product

u

v

u﹡v<0

obtuse

u﹡v=0

right angle

u﹡v>0

acute

The dot product can be used for many geometric tests

Dot Product

u

v

||v||

|d|=||u||-1u・v=||v|| cos θ

d=(u·v)(u·u)-1 u

~u · ~v = ||~u|| ||~v|| cos ✓~u · ~u = ||~u||2

~u · ~v = ~v · ~u~u · (~v + ~w) = ~u · ~v + ~u · ~w(r~u) · (s~v) = sr(~u · ~v)

Bounding Volumes

Sphere Axis Aligned Bounding Box (AABB)

Oriented bounding box (OBB)

better bound, better culling

faster test, less memory

AABBRepresentations

min — max min — widths center — radius

AABB IntersectionsProject min and max points on x-axis and y-axis AABB intersects if the projected intervals intersect

AABB Intersections• Intersection test for min-max representation

class AABB: def __init__(self, mini, maxi): self.mini = mini self.maxi = maxi def __str__(self): return “[{},{}]”.format(str(self.mini), str(self.maxi) def intersect(self, other): if self.maxx < other.minx or self.minx > self.maxx: return False if self.maxy < other.miny or self.miny > self.maxy: return False return True

Intersection Ray Circle

||~p+ t~d� ~c|| = r

(~p+ t~d� ~c) · (~p+ t~d� ~c) = r2

(~m+ t~d) · (~m+ t~d) = r2 with ~m = ~p� ~c

(~d · ~d)t2 + 2(~m · ~d)t+ (~m · ~m� r2) = 0

t = �(~m · ~d)±q(~m · ~d)2 � ~m · ~m+ r2

r

C

P

d

{P+td | t>0}Ray given by origin and direction

Solve for the points that lie on the outside of the circle

Check whether they lie on the ray

Intersection Ray CircleIntersect twice Intersect tangentially No intersection

False Intersection Ray starts inside

Intersection Ray AABB

Horizontal Slab

Vertical Slab

Use intersection with horizontal and vertical slab.

If there is no or only one intersection, then the ray cannot intersect the AABB.

If the intersections do not overlap, then the ray does not intersect the AABB.

top related