D

#### Daniel Moore

=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this

quiz until 48 hours have elapsed from the time this message was

sent.

2. Support Ruby Quiz by submitting ideas and responses

as often as you can.

3. Enjoy!

Suggestion: A [QUIZ] in the subject of emails about the problem

helps everyone on Ruby Talk follow the discussion. Please reply to

the original quiz message, if you can.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

RSS Feed: http://rubyquiz.strd6.com/quizzes.rss

Suggestions?: http://rubyquiz.strd6.com/suggestions

-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=

=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-

## Geometric Intersections (#233)

HI=E2=9F=82RB

This week's quiz is to detect the intersections of various geometric

elements: circles, lines, and polygons.

A circle is defined by a point and a radius.

point =3D [6, 3]

radius =3D 5

a =3D Circle.new(point, radius)

A line can be defined by two points, or a point and a slope.

p1 =3D [0, 0]

p2 =3D [4, 2]

line =3D Line.new(p1, p2)

slope =3D 0.5

line =3D Line.new(p1, slope)

A polygon can be defined as a collection of points.

b1 =3D [2, 9]

b2 =3D [1, 3]

b3 =3D [7, 5]

b =3D Polygon.new(b1, b2, b3)

def intersect(a, b)

# Should return true or false indicating whether or not

# a and b intersect. a and b can be any circle, line or

# polygon.

end

You may also find it more natural to define a.intersect(b) or

b.intersect(a). The relation should be symmetric and reflexive, though

not transitive.

Which methods you choose to add to the geometric elements is up to

you, the only hard requirement is that the intersect method(s) return

the correct truth values.

Have fun!

Extra Credit: handle the "edge" cases of the polygon comprised of one

point (a single point) or two points (a line segment).

Extra Extra Credit: Provide a graphical and colorful output indicating

intersections.

--=20

-Daniel

http://rubyquiz.strd6.com