4
$\begingroup$

I have drawn a triangle using Line graphics primitive and Graphics3D function:

 Graphics3D[Line[{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 0, 0}}], 
 Axes -> False, Boxed -> True, AspectRatio -> 1]

enter image description here

But in the shape I get, the vertices of triangle do not coincide with the vertices of the box, how can I solve this problem?

$\endgroup$
  • 4
    $\begingroup$ I think you can try PlotRangePadding -> 0 $\endgroup$ – xslittlegrass May 16 '13 at 5:20
5
$\begingroup$

The comment is right, but here is a thought. If you'd like a cube you should use Cuboid and leave the 3D box for the role it plays - to put things in a better 3D perspective (if needed). Then you precisely control all coordinates. You could try something like

Graphics3D[{
  {Red, Opacity[.7], Polygon[{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}]},
  {Opacity[.2], Cuboid[{0, 1, 0}, {1, 0, 1}]}
  }, Axes -> False, Boxed -> False, AspectRatio -> 1]

enter image description here

$\endgroup$
  • $\begingroup$ Very nice, thank you very much. $\endgroup$ – Ahmad A May 16 '13 at 5:55
3
$\begingroup$

As noted by xslittlegrass you can get coincident vertices by instructing Graphics3D not to use padding of the plot range, by using PlotRangePadding -> 0.

AspectRatio controls the two dimensional image aspect ratio rather the proportions of the three dimensional rendering which is what I expect you intended; for that use BoxRatios.

Specifying Boxed -> True should (by default) produce a graph without axis lines shown, therefore the Axes -> False option is redundant.

Graphics3D[
 Line[Tuples[{0, 1}, 3][[{5, 3, 2, 5}]]],
 Boxed -> True,
 PlotRangePadding -> 0
]

enter image description here

$\endgroup$
  • $\begingroup$ Brilliant, thank you very much. $\endgroup$ – Ahmad A May 16 '13 at 7:16
  • $\begingroup$ @Ahmad You're welcome. $\endgroup$ – Mr.Wizard May 16 '13 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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