5

I need to export a circle drawn in 3D with a specific point of view to a PDF file. This is easy to do. However, the exported circle is made of tons of non-connected small bits. I need the whole circle to be a single piece in vectorial form. How can we do this ? Take note that I also need the three axes to be exported too (they are not cutted into small parts, which is what I want).

Here's the code itself :

ParametricPlot3D[
    {Cos[p], Sin[p], 0}, {p, 0, 2 Pi},
    PlotStyle -> {Directive[AbsoluteThickness[1], GrayLevel[0.5]]},
    PlotPoints -> 100,
    PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-0.5, 0.5}},
    Boxed -> False,
    Axes -> True,
    Ticks -> None,
    AxesStyle -> Directive[GrayLevel[0.5], Dashed],
    AxesOrigin -> {0, 0, 0},
    ImageSize -> {750, 750},
    ViewAngle -> 25 Pi/180,
    ViewPoint -> {1, 1, 1},
    SphericalRegion -> True,
    Method -> {"RotationControl" -> "Globe"}
    ]

Exporting to a PNG or JPG file is not an option here. I need the vectorial form of the curve, as a single piece (I'll also have to do the same with another curve, much more complicated than a simple circle).

Cham
  • 4,093
  • 21
  • 36
  • You realize, that the circle is a primitive, easily parametrized and, in theory, its 3d form projected onto the 2d computer screen can be calculated to be some ellipse, while your "much more complicated curve" can only be calculated at a set of discrete points and the PDF format probably doesn't have these tools built in? I.e. your curve, at best, can be represented as some kind of spline which is not necessarily exactly what its real shape is. – LLlAMnYP Mar 18 '16 at 16:09
  • @LLlAMnYP, all my 2D curves (even if they are complicated) can be exported to a single piece in a PDF file. I don't have any problem with 2D. 3D is "special" in MMA, even to draw a simple circle. – Cham Mar 18 '16 at 16:17
  • I'm afraid, I don't follow your usage of the term "single-piece". I thought, you meant, that if you zoom in, the curve is not smooth, but a collection of straight segments. That is the case for 2d plots as well. (the Circle[] primitive is fundamentally different). – LLlAMnYP Mar 18 '16 at 16:20
  • @LLlAMnYP, single piece means connected small lines. Not just a pack of small unrelated bits. All of my 2D curves are exported fine as single entities. 3D doesn't. – Cham Mar 18 '16 at 16:21
  • Ok, I see what you mean here. Corel is showing the same thing. – LLlAMnYP Mar 18 '16 at 16:24
  • How exactly do you export the 3d scene, avoiding rasterization? – LLlAMnYP Mar 18 '16 at 16:24
  • In MMA version 7 (I think it's a feature of this version only), I simply select the picture, and export it using the contextual menu. Various options there : PNG, JPEG, PDF, EPS, etc. – Cham Mar 18 '16 at 16:25
  • We can also export the 3D graphics using the command Export["graphics.pdf", graphics]. – Cham Mar 18 '16 at 16:28
  • Yes, I had a look at related topics, workarounds are available in v10 but the line comes out as a collection of separate segments. In all these cases, all I can suggest is to construct the projection onto the 2d plane within MMA and export the 2d scene. On the other hand, as you want axes, which are not reduced to graphics primitives in the InputForm of Graphics3D the only hope may be a superposition of the primitives and an empty plot with axes. – LLlAMnYP Mar 18 '16 at 16:32
  • The empty plot with axes isn't a problem. Superposition shouldn't be a problem neither. But how do you construct a proper 2D scene from the 3D one ? – Cham Mar 18 '16 at 16:33
  • As you no doubt can guess, MMA already does it when it finds the 2D screen coordinates to display the scene defined by 3D coordinates. It is covered in the documentation, somewhere around ViewMatrix and friends, I've been looking at that not too long ago. I'll have another look, see if I can find it quickly. – LLlAMnYP Mar 18 '16 at 16:35
  • Sorry, there's not a straightforward description in the docs, although the ViewMatrix article is somewhat useful. Google search for projecting 3d to 2d gives useful results, such as Wiki and this SO question. The theory behind this is not too complicated, but implementing it may be tedious. In general you're probably going to end up with a 4x4 matrix m and will be doing something like (m.{x,y,z,1})[[;;2]] to get an x-y projection of point xyz then /.Graphics3D->Graphics. – LLlAMnYP Mar 18 '16 at 16:49
  • 3
    This article http://media.pearsoncmg.com/aw/aw_lay_linearalg_updated_cw_3/cs_apps/lay03_02_cs.pdf discusses 3d projection onto 2d in very simple terms. It's an interesting problem, but I really don't have the time to roll an implementation right now. – LLlAMnYP Mar 18 '16 at 16:55
  • Consider using BSplineCurve[] instead. – J. M.'s missing motivation Mar 18 '16 at 18:25
  • The probable reason, why MMA breaks up the continuous line into segments, is because it needs to determine, whether parts of the line are obscured by other objects or not, and that is likely done on a segment-by-segment basis. – LLlAMnYP Mar 19 '16 at 16:01
  • @LLlAMnYP, this is exactly what I think (actually, I'm sure of it). I already started a topic on this here : http://mathematica.stackexchange.com/questions/109742/how-to-turn-off-depth-sorting-of-3d-curves-for-manipulate, but it has received negative comments and votes ! So do you think there's a way to turn off the depth sorting of 3D curves, in MMA ? That would be awesome ! – Cham Mar 19 '16 at 16:41
  • Well, I doubt it's to do with performance, and the answer you got there is that it's only for export purposes. That seems true. As it stands, you're better off implementing your own projection method. Since Graphics3D uses GraphicsComplex when rendering anything more complicated than primitives, I think it should be very easy, once you figured out the transformation and projection matrices. – LLlAMnYP Mar 19 '16 at 17:06
  • @LLlAMnYP, so you don't know any way to turn off the depth sorting of 3D output ? – Cham Mar 19 '16 at 17:19
  • I'm close to confident, that is done in low-level code, analogous to rendering. – LLlAMnYP Mar 19 '16 at 18:46
  • Hmm, thanks for the comment. Then there is no solution to my problem, or to accept curves cut into small parts, or a PNG image only. This is -1 for MMA ! – Cham Mar 19 '16 at 19:59
  • I have revisited this topic and came up with a partial solution to your problem. Writing up an answer now. – LLlAMnYP May 09 '18 at 13:32
  • This problem is now solved in my self-answered question. The wrapper function can convert lines from Graphics3D to Graphics which, when exported to PDF do not undergo depth-sorting and remain as single, grouped objects, as the OP desires. Hence, I mark this question as a duplicate. – LLlAMnYP May 09 '18 at 15:17

1 Answers1

1

This does the job

Graphics[{Circle[{0, 0}, {4, 2}], Dashed, Line[{{-3, -2}, {3, 2}}],Line[{{3, -2}, {-3, 2}}], Line[{{0, -1.5}, {0, 1.5}}]}]

circle

When exported to PDF the picture has a minimal number of elements. For the case of arbitrarily oriented in 3d circle one needs to work out formulas for the ellipse.

yarchik
  • 18,202
  • 2
  • 28
  • 66
  • This can't work. The center of this ellipse is not the same as the center of a tilted circle in 3D. Perspective effects are more complicated. – Cham Mar 18 '16 at 23:27