Message Boards Message Boards

0
|
2309 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Elementary Question about using Rules

Posted 10 years ago

I'm a beginner in Mathematica; I have a question on a Mathematica homework set, that seems to me should be pretty simplistic, but I seem to be hitting a wall. My error must be completely obvious, but can someone please teach me the proper way of doing this? In the following example, change every Point to a Circle with radius 1/2, centered around the point, using a Rule application.

The code give was

Graphics[{PointSize[.02],Point[{9,5}],Point[{2,-5}],Point[{5,5}],Point[{3,6}],Point[{1,1}],Point[{5,-7}],Point[{-7,4}], Point[{6,-10}],Point[{-6,-2}],Point[{0,8}],Point[{1,4}],Line[{{1,4},{2,5}}],Point[{2,5}]}]

I altered it by

Graphics[{PointSize[.02],Point[{9,5}],Point[{2,-5}],Point[{5,5}],Point[{3,6}],Point[{1,1}],Point[{5,-7}], Point[{-7,4}],Point[{6,-10}],Point[{-6,-2}],Point[{0,8}],Point[{1,4}],Line[{{1,4},{2,5}}],Point[{2,5}] /.{a_Point->Circle[{a},.5]

Of course, this leads the program into entering the entire Point{x,y} into the coordinate place in the circle. Help please?

POSTED BY: Kacey Price
2 Replies

Dear Kacey,

this should work:

Graphics[{PointSize[.02], Point[{9, 5}], Point[{2, -5}], 
   Point[{5, 5}], Point[{3, 6}], Point[{1, 1}]}] /. 
 Point[{x_, y_}] -> Circle[{x, y}, 1/2]

I only demonstrate it for few points. It is not the best way, because the leading PointSize will still be in the list, but it does work because PointSize will simply be ignored.

If you want the PointSize directive to be deleted to have a clearer command

Graphics[Drop[{PointSize[.5], Point[{9, 5}], Point[{2, -5}], 
    Point[{5, 5}], Point[{3, 6}], Point[{1, 1}]} /. 
   Point[{x_, y_}] -> Circle[{x, y}, 1/2], 1]]

does the trick. The output should be identical.

Cheers, M.

POSTED BY: Marco Thiel
Posted 10 years ago

Worked beautifully-thanks!

POSTED BY: Kacey Price
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract