1
$\begingroup$

Given the following line of code,

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}]}, 
  AspectRatio->Automatic] 

the objective is to replace every Point as a Circle with a radius of 1/2 centered around the same coordinates. The question asks for this to be done using a ReplaceAll (aka Rule) function.

I know how to replace points with circles. Just add /. Point -> Circle to the end of that block. And it goes from plotted dots to circles.

But how do I change the radius to 1/2 using the Rule function? Because when I replace Point with Circle, it results in Circle of radius 1. The only way I could think was something like /. Point[{ _ , _ }] -> Circle[{ _ , _ }, 0.5], but that of course didn't work.

Any help is much appreciated!

$\endgroup$

closed as off-topic by Yves Klett, MarcoB, Bob Hanlon, Mr.Wizard Jun 25 '15 at 6:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Yves Klett, MarcoB, Bob Hanlon, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ You could try yourgraphics /. Point[x_] -> Circle[x, 1/2] $\endgroup$ – Fred Simons Jun 24 '15 at 14:29
  • 1
    $\begingroup$ Look up Blank. $\endgroup$ – J. M. is away Jun 24 '15 at 14:29
  • $\begingroup$ This is my take on using Blank. /. Point[{_, _}] -> Circle[#, 0.5] It doesn't work, however. Can someone please explain what I did wrong/need to change? $\endgroup$ – A is for Ambition Jun 24 '15 at 14:34
  • $\begingroup$ @FredSimons it doesn't work :( $\endgroup$ – A is for Ambition Jun 24 '15 at 14:36
  • 2
    $\begingroup$ On my computer, it works. But it might be that somewhere you did an assignment to x. Then use :> instead of -> (RuleDelayed instead of Rule) $\endgroup$ – Fred Simons Jun 24 '15 at 15:12
3
$\begingroup$
g = 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}]}, 
   AspectRatio -> Automatic];
g /. Point -> (Circle[#, .5] &)

Mathematica graphics

$\endgroup$
  • $\begingroup$ Can you explain what the &'s purpose is? How does it affect the output? Thanks very much! $\endgroup$ – A is for Ambition Jun 24 '15 at 14:31
  • $\begingroup$ Also, how come Circle[#, .5] & must be enclosed in standard parentheses (as opposed to square/curly/no brackets)? $\endgroup$ – A is for Ambition Jun 24 '15 at 14:44
  • 2
    $\begingroup$ @AisforAmbition, questions like your first can be easily answered using the built-in documentation. Just highlight '&' and press F1. You need the second hit (Function). As to your second question: This has to do with operator precedence. Precedence of -> is higher than & and the pure function Circle[#, .5] & needs to be protected from being read as (Point -> Circle[#, .5] )&. You can find the precedence table on the tutorial/OperatorInputForms page of the documentation. $\endgroup$ – Sjoerd C. de Vries Jun 24 '15 at 14:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.