Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to draw a cross as an inset in a Graphics environment. I tried the following:

Graphics[{Inset[Style["\[Cross]", 100], {0, 0},{Center,Center}], Circle[]}, 
     Frame -> True]

Inset of cross in circle

Unfortunately, the {Center,Center} command for specifying the exact point of the cross that is drawn at the {0,0} position does not use the intercept of the two parts of the cross. Is there an easy way to produce a cross using graphics primitives rather than special characters? I have not done much with graphics yet and would really appreciate your help.

share|improve this question
    
When I evaluated your code on OS X using Mathematica V9, the cross was perfectly centered. –  m_goldberg Feb 5 '13 at 23:16
add comment

1 Answer 1

up vote 4 down vote accepted

Nice & easy:-

a = 0.2; t = 6;
Graphics[{Circle[],
  Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a],
  Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
 Frame -> True, ImageSize -> 250]

enter image description here

Using Inset ensures the resulting X stays within the 2 a bounds specified. The simpler red X shown, spills over slightly due to the thickness. The cross is also shown in green.

a = 0.2; t = 6;
Show[Graphics[{Circle[],
   AbsoluteThickness[t], Red,
   Line[{{-a, -a}, {a, a}}],
   Line[{{-a, a}, {a, -a}}]},
  Frame -> True, ImageSize -> 350],

 Graphics[{Circle[],
   Line[{{0, -1}, {0, 1}}],
   Line[{{-1, 0}, {1, 0}}],
   Line[{{a, -1}, {a, 1}}],
   Line[{{-1, a}, {1, a}}],
   Line[{{-a, -1}, {-a, 1}}],
   Line[{{-1, -a}, {1, -a}}],
   Inset[Style["\[Cross]", 100, Green], {0, 0}, {Center, Center}],
   Inset[Graphics[{AbsoluteThickness[t],
      Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a],
   Inset[Graphics[{AbsoluteThickness[t],
      Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
  Frame -> True, ImageSize -> 350]]

enter image description here

Addendum

Inset X's can be made to scale. But first, using non-inset lines scales straight away:

a = 0.2; t = 6;
 Graphics[{Circle[], AbsoluteThickness[t], Red,
  Line[{{-a, -a}, {a, a}}], Line[{{-a, a}, {a, -a}}]},
 Frame -> True, ImageSize -> 250, AspectRatio -> 0.4]

enter image description here

Inset lines' sizes are not affected by the enclosing graphic's AspectRatio:

a = 0.2; t = 6; r = 0.4;
Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a], 
  Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
 Frame -> True, ImageSize -> 250, AspectRatio -> r]

enter image description here

Adding a factor to the insets can apply scaling:

a = 0.2; t = 6; r = 0.4;
Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, -a r}, {a, a r}}]}], {0, 0}, Center, 2 a],
  Inset[Graphics[{AbsoluteThickness[t],
     Line[{{-a, a r}, {a, -a r}}]}], {0, 0}, Center, 2 a]},
 Frame -> True, ImageSize -> 250, AspectRatio -> r]

enter image description here

share|improve this answer
1  
Using inset also makes it possible to locate the cross anywhere: a = 0.2; t = 6; Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t], Line[{{-a, -a}, {a, a}}]}], {1, 0}, Center, 2 a], Inset[Graphics[{AbsoluteThickness[t], Line[{{-a, a}, {a, -a}}]}], {1, 0}, Center, 2 a]}, Frame -> True, ImageSize -> 250] shifts the cross to the right. –  Apatura Feb 5 '13 at 15:42
    
Just out of interest: why does the cross stay symmetrically if I combine it with a plot with differently scaled axes? Doesn't the a refer to the values of the x and y values where the lines of the cross end? –  Apatura Feb 5 '13 at 16:00
1  
@Apatura - You could add aspect ratios to the insets, or scale them as shown in the addendum to my post. –  Chris Degnen Feb 5 '13 at 18:28
    
Interestingly, the green cross is not offset on Mac OSX. –  Chris Degnen Feb 5 '13 at 18:30
    
Thank you very much, your answer definitely helped me understanding the use of the Graphics and Inset options. –  Apatura Feb 5 '13 at 22:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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