4
$\begingroup$

I want to create two planes in 3D space (looks like the following figure 1). Firstly, I try to use the ContourPlot3D and Polygon, but both of them will generate some unexpected grid or triangle (looks like the following figure 2) when "save as" or "export" the planes to PDF, so I have to replace these two function with Line (looks like the following figure 3), but the codes are long and complicate. Later, I find these codes are regular, so want to simplify them, but this is difficult for me. Hope you can help me simplify the plot codes or provide a new method to obtain the ideal PDF, Note: I want to have a 3D vector graphics(PDF is better). Thanks.

The parameters of these lines are regular, which looks like the following:

x = 0;
y = 10;
Graphics3D[{
  Thickness[0.002], Black, Line[{{x, -y, 0}, {x, y, 0}}],
  Thickness[0.002], Black, Line[{{x, -y, 80}, {x, y, 80}}],
  Thickness[0.002], Black, Line[{{x, y, 0}, {x, y, 80}}],
  Thickness[0.002], Black, Line[{{x, -y, 0}, {x, -y, 80}}],
  Thickness[0.002], Black, Line[{{-y, x, 0}, {y, x, 0}}],
  Thickness[0.002], Black, Line[{{-y, x, 80}, {y, x, 80}}],
  Thickness[0.002], Black, Line[{{y, x, 0}, {y, x, 80}}],
  Thickness[0.002], Black, Line[{{-y, x, 0}, {-y, x, 80}}]
  }, BoxRatios -> {1, 1, 1}]

How to simplify them. Thanks!

Here are the codes of other two functions

sx = 10;
ContourPlot3D[{{x == 0}, {y == 0}}, {x, -sx, sx}, {y, -sx, sx}, {z, 0,
   80}, Mesh -> None, 
 ContourStyle -> {Directive[Blue, Opacity[0.01]], 
   Directive[Red, Opacity[0.01]]}, PlotRange -> All]

Graphics3D[{Thickness[0.002], Black, Line[{{0, 0, 0}, {0, 0, 80}}], 
  Blue, Opacity[.1], 
  Polygon[{{-sx, 0, 0}, {sx, 0, 0}, {sx, 0, 80}, {-sx, 0, 80}}], Red, 
  Opacity[.1], 
  Polygon[{{0, -sx, 0}, {0, sx, 0}, {0, sx, 80}, {0, -sx, 80}}]}, 
 BoxRatios -> {1, 1, 1}]

Figure 1

enter image description here

Figure 2

enter image description here

Figure 3

enter image description here

$\endgroup$
10
  • 1
    $\begingroup$ The question is unclear to me. What's the input here? What are f and expr? Are you looking for something like func[x_, y_]={{x, y, 30}, {-x, -y, 30}, {y, x, 30}, {-y, -x, 30}}; func[1, 2]? $\endgroup$ – xzczd Jul 19 '20 at 6:01
  • $\begingroup$ OK, so you've over-simplified the question. Then, have you tried Hyperplane or InfinitePlane? $\endgroup$ – xzczd Jul 19 '20 at 7:43
  • $\begingroup$ @xzczd, the two functions you mentioned are introduced after the Mathematica version 10, however, they can not "save as" or "export" 3D vector graphics after the version 9.0. Can you provide me another solution? Thanks. $\endgroup$ – likehust Jul 19 '20 at 7:56
  • $\begingroup$ …Do you mean you're in v9? If so, please mention this in the question. $\endgroup$ – xzczd Jul 19 '20 at 8:01
  • $\begingroup$ Just tested in v9, Win10, the following works well: Export["a.pdf", ContourPlot3D[{x == 0, y == 0}, {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, Mesh -> None, ContourStyle -> Opacity[0.1], Ticks -> None]] // SystemOpen I guess you didn't add Mesh->None? $\endgroup$ – xzczd Jul 19 '20 at 8:07
1
$\begingroup$

How about AnglePath?:

pts = AnglePath[{1/2, -1/2}, Table[90 °, 4]];

{{#, 0, #2} & @@@ pts, {0, #, #2} & @@@ pts} // Line // Graphics3D

Since there's a design change for export of Graphics3D[…] to PDF format after v9 and it seems to be hard to bring back the old behavior in newer versions, I think the easiest work-around is to stay in v9 and implement AnglePath ourselves. Luckily J.M. has already implemented it here. So we just need to modify the code to:

pts = anglePath[{1/2, -1/2}, Table[90 °, {4}]];

{{#, 0, #2} & @@@ pts, {0, #, #2} & @@@ pts} // Line // Graphics3D

Notice I've modified the syntax of Table, you may check this post for more info about the syntax change.

$\endgroup$
7
  • $\begingroup$ Thanks. It's become concise exactly, but if you noticed that it fails to generate vector graphics. $\endgroup$ – likehust Jul 20 '20 at 1:45
  • 1
    $\begingroup$ @likehust Then I believe your approach won't generate vector graphics, either, because it's a combination of Graphics3D and Line, just like mine. Can you clarify the meaning of "vector graphics" in your mind? $\endgroup$ – xzczd Jul 20 '20 at 3:24
  • $\begingroup$ Thanks for your reply. the vector graphics I want is same as here, the AnglePath is introduced on version 10, so it can not "save as" or "export" to a 3D vector graphics(but can generate 2D vector graphics), and I have tested the result. $\endgroup$ – likehust Jul 20 '20 at 3:49
  • $\begingroup$ @likehust "the AnglePath is introduced on version 10, so it can not "save as" or "export" to a 3D vector graphics(but can generate 2D vector graphics" I don't understand what you mean. The output of AnglePath is just a list of numbers whose dimension is $n×2$, and I've transformed it to a $n×3$ list with {#, 0, #2} & @@@. The output of my code is undoubtedly 3D vector grahpic. Have you tried my code? $\endgroup$ – xzczd Jul 20 '20 at 4:15
  • $\begingroup$ From V10, the exported 3D PDF graphics are bitmaps, but 2D PDF graphics are vectors. Maybe the V9 is the final version that can "save graphic as" and "export" 3D and 2D PDF vector graphics at the same time. So, AnglePath , introduced on V10.1 in 2015, can not generate 3D PDF vector graphics, it only can obtain bitmap figure when export or save graphic as. I have tested your code, thanks. $\endgroup$ – likehust Jul 20 '20 at 7:38
3
$\begingroup$
f[x_, y_] := {{x, y, 30}, {-x, -y, 30}, {y, x, 30}, {-y, -x, 30}}

x = 1;
y = 2;

Apply[f, List[x, y]]

{{1, 2, 30}, {-1, -2, 30}, {2, 1, 30}, {-2, -1, 30}}

$\endgroup$
1
  • $\begingroup$ Sorry, I didn't propose a clear question. But, you can proceed to give a better solution. Thanks. $\endgroup$ – likehust Jul 19 '20 at 7:58

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.