0

I am doing the following to create a line loop (circle) in Mathematica:

(* generate points on a circle *)
pts = Table[{a Cos[t], a Sin[t], 0}, {t, 0, 2 Pi, 0.1}];
(* add last segment *)
pts = Append[pts, {a, 0, 0}];
(* build tr... *)
(* ... *)
(* draw *)
Graphics3D[GeometricTransformation[Line[pts], tr]]

Is there a better way to create a table so that the first point is repeated? Append[] above looks bad.

I am not using Circle[] because I need to transform the circle in a Graphics3D[]. I am not using ParametricPlot3D because to my knowledge I can't put that inside a GeometricTransformation[].

Thanks for any suggestions.

Regards

M-V
  • 5,167
  • 7
  • 52
  • 55
  • 1
    `ParametricPlot3D` returns a `Graphics3D` object. The first part of the graphics object is a list of graphics primitives and directives, and geometric transforms can be applied to that list. – Brett Champion Jun 27 '11 at 16:06

3 Answers3

3

Well, how about

segs=64.;
pts = Table[{a Cos[t], a Sin[t], 0}, {t, 0, 2 Pi, 2 Pi/segs}];

which creates a list with segs+1 segments, the last of which is the same as the first?

acl
  • 6,490
  • 1
  • 27
  • 33
  • @Leonid yes, i happened to look at SO at the right time for once :) – acl Jun 27 '11 at 15:53
  • @Leonid I'd love it if my FF tab with SO would make a beep when there's a new post. Probably should look into ways of letting MMA deal with that... ;-) – Sjoerd C. de Vries Jun 27 '11 at 16:01
  • @Sjoerd well, with code to get the titles of new questions (which is given in some answer here by someone, maybe even you) and ScheduledTasks, this should be relatively easy (if maybe resource intensive) – acl Jun 27 '11 at 16:05
  • @acl Technically speaking, your code doesn't create a polygon, just a list of 3D coordinates. You need to put `Polygon@` in font of it. And a Polygon doesn't need to have the first and last coordinates to be the same. That's only necessary for a `Line` that you want to close. So, you better write `segs=64.; poly= Polygon@Table[{a Cos[t], a Sin[t], 0}, {t, 0, 2 Pi-2 Pi/segs, 2 Pi/segs}];` – Sjoerd C. de Vries Jun 27 '11 at 16:11
  • @acl checking once a minute should be fine (as long as the others don't use this). I always suspected Mr.Wizard was doing something like that ;-) Come to think of him, he must be on vacation. Haven't heard much of him lately. – Sjoerd C. de Vries Jun 27 '11 at 16:15
  • @sjoerd right, it's not actually a polygon. as for the last point, the question was specifically about getting the last point to be the same as the first, or so I read it ("Is there a better way to create a table so that the first point is repeated"). – acl Jun 27 '11 at 16:17
  • @sjoerd actually, I sort of assumed Mr.Wizard is a collective entity of writers and programmers, who sleep and reply to SO questions in shifts... – acl Jun 27 '11 at 16:19
  • @acl Well, I sort of proved that in this question http://stackoverflow.com/q/5845436/615464. – Sjoerd C. de Vries Jun 27 '11 at 16:34
  • @acl, @Sjoerd I was suspecting the same for some time. But now I think he is a single person. – Leonid Shifrin Jun 27 '11 at 17:00
  • @Sjoerd, acl, Leonid, you guys crack me up! There is no automation or Borg Collective here, just an unemployed Joe with sleep problems, hoping to help others where I can. – Mr.Wizard Aug 24 '11 at 06:09
  • @Leonid, ps: if anyone appeared to be a consortium of authors, I would have thought it would be you, and I mean that as nicely as possible. – Mr.Wizard Aug 24 '11 at 06:12
  • @Mr.Wizard, Sjoerd If you guys find the Joe part to be a problem, why don't you contact WRI? I am sure your skills could be put to lots of interesting uses there, and you'll be doing for fun and profit things similar to those you are anyway doing for fun. The coming Tech. Conference should also be a great place to meet people and see what is currently going on with mma. – Leonid Shifrin Aug 24 '11 at 08:20
  • @Sjoerd, Mr. Wizard (repeating because SO now only allows one person to be notified) If you guys find the Joe part to be a problem, why don't you contact WRI? I am sure your skills could be put to lots of interesting uses there, and you'll be doing for fun and profit things similar to those you are anyway doing for fun. The coming Tech. Conference should also be a great place to meet people and see what is currently going on with mma. – Leonid Shifrin Aug 24 '11 at 08:21
  • @Leonid @ Leonid (because there's an echo in here) that would be great, but I am afraid I don't meet the requirements, in a variety of ways. I appreciate the vote of confidence however. – Mr.Wizard Aug 24 '11 at 08:51
  • @Mr. Wizard Well, you never know. WRI is unlike many other places in many ways, I believe. – Leonid Shifrin Aug 24 '11 at 08:58
  • @Leonid I guess I would like it very much, but moving to Champaign would be a problem given that my significant other has a very good job here. – Sjoerd C. de Vries Aug 24 '11 at 11:39
  • @Mr.Wizard It's amazing how you succeed in tickling my curiosity with a few words. But this is probably not the place to discuss that. – Sjoerd C. de Vries Aug 24 '11 at 11:47
  • @Leonid ... but perhaps they might have telecommuting jobs. Tech conference would be nice too. I'd surely like to meet my fellow answerers. Not sure though whether I could afford the time and money. – Sjoerd C. de Vries Aug 24 '11 at 20:21
2

You could draw the curve as a faceless polygon:

pts = Table[{a Cos[t], a Sin[t], 0}, {t, 0, 2 Pi, 0.1}];
Graphics3D[GeometricTransformation[{FaceForm[],EdgeForm[Thin],Polygon[pts]}, tr]]

or

Graphics3D[{FaceForm[],EdgeForm[Thin],GeometricTransformation[Polygon[pts], tr]}]
Brett Champion
  • 8,497
  • 1
  • 27
  • 44
1

If Append "looks bad," perhaps this is more aesthetic?:

pts = {##,#}& @@ pts

Or, if you are of a more obscure persuation, perhaps:

ArrayPad[pts, {0, 1}, "Periodic"]
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125