On 14/11/2014 7:18 AM, Alexander Shenkin wrote:
Hello all,
I have a set of points in 3D space that represent vertices of a
non-convex polyhedron. I would like to plot this polyhedron, and have
been trying to do so with rgl.triangles, but to no avail. I imagine I
don't understand what rgl.triangles expects for arguments. I have
constructed the triangles myself, and have the three vertices of each
triangle. I am then passing these to rgl.triangles in the x,y & z
arguments.
I end up with unexpected results (see http://i.imgur.com/BaKfzn7.png).
Might someone advise me about the structure of arguments that
rgl.triangles expects (or perhaps a better way to go about this)?
?rgl.triangles doesn't help much with this particular issue...
I can't tell what you think is wrong. Your arguments look right.
Here's some general advice:
1. Don't use rgl.triangles(). Use triangles3d(). This won't affect
the geometry, but it handles colours and other attributes more rationally.
2. Think about using a triangle mesh instead of triangles3d(). You
only need to specify each vertex once, instead of
many times as your current code does.
3. Put together a simpler example, e.g. two triangles, and see if that
works. Then build up from there.
Duncan Murdoch
Thanks,
Allie
The code, where rows 2,3,4 are one triangle, 5,6,7 the next, etc
(apologies - don't know how to serialize a dataframe to make it easy to
suck into one's environment):
rgl.triangles(tri_df[,1],tri_df[,2],tri_df[,3],col=heat.colors(nrow(tri_df)),alpha=.2)
> tri_df
x y z
2 -2.9970624 -0.1327280 8.0
3 -1.3358202 3.8762849 4.9
4 3.5380065 0.6652143 9.1
5 -1.3358202 3.8762849 4.9
6 1.4644874 3.6145922 5.3
7 3.5380065 0.6652143 9.1
8 1.4644874 3.6145922 5.3
9 1.9606671 -3.8269811 4.5
10 3.5380065 0.6652143 9.1
11 1.9606671 -3.8269811 4.5
12 -3.5337687 3.6772923 3.9
13 3.5380065 0.6652143 9.1
14 -3.5337687 3.6772923 3.9
15 -5.6586500 1.2726665 3.5
16 3.5380065 0.6652143 9.1
17 -5.6586500 1.2726665 3.5
18 3.8327817 -2.8895994 3.4
19 3.5380065 0.6652143 9.1
20 3.8327817 -2.8895994 3.4
21 6.0806691 -0.4852461 2.2
22 3.5380065 0.6652143 9.1
23 6.0806691 -0.4852461 2.2
24 -0.5109254 -6.7807784 0.5
25 3.5380065 0.6652143 9.1
26 -0.5109254 -6.7807784 0.5
27 2.3503422 -6.2742244 1.8
28 3.5380065 0.6652143 9.1
29 2.3503422 -6.2742244 1.8
30 5.4741865 -1.1803740 0.3
31 3.5380065 0.6652143 9.1
32 5.4741865 -1.1803740 0.3
33 5.7888812 -0.3589635 2.7
34 3.5380065 0.6652143 9.1
35 5.7888812 -0.3589635 2.7
36 -3.1939122 -2.4080958 5.4
37 3.5380065 0.6652143 9.1
38 -3.1939122 -2.4080958 5.4
39 -1.4732303 -3.9331403 4.9
40 3.5380065 0.6652143 9.1
41 -1.4732303 -3.9331403 4.9
42 -3.4863074 0.3092904 6.8
43 3.5380065 0.6652143 9.1
44 -3.4863074 0.3092904 6.8
45 0.8019969 -2.2620347 7.2
46 3.5380065 0.6652143 9.1
47 0.8019969 -2.2620347 7.2
48 -2.9970624 -0.1327280 8.0
49 3.5380065 0.6652143 9.1
50 -1.3358202 3.8762849 4.9
51 -2.9970624 -0.1327280 8.0
52 6.4508128 -2.4488802 0.3
53 1.4644874 3.6145922 5.3
54 -1.3358202 3.8762849 4.9
55 6.4508128 -2.4488802 0.3
56 1.9606671 -3.8269811 4.5
57 1.4644874 3.6145922 5.3
58 6.4508128 -2.4488802 0.3
59 -3.5337687 3.6772923 3.9
60 1.9606671 -3.8269811 4.5
61 6.4508128 -2.4488802 0.3
62 -5.6586500 1.2726665 3.5
63 -3.5337687 3.6772923 3.9
64 6.4508128 -2.4488802 0.3
65 3.8327817 -2.8895994 3.4
66 -5.6586500 1.2726665 3.5
67 6.4508128 -2.4488802 0.3
68 6.0806691 -0.4852461 2.2
69 3.8327817 -2.8895994 3.4
70 6.4508128 -2.4488802 0.3
71 -0.5109254 -6.7807784 0.5
72 6.0806691 -0.4852461 2.2
73 6.4508128 -2.4488802 0.3
74 2.3503422 -6.2742244 1.8
75 -0.5109254 -6.7807784 0.5
76 6.4508128 -2.4488802 0.3
77 5.4741865 -1.1803740 0.3
78 2.3503422 -6.2742244 1.8
79 6.4508128 -2.4488802 0.3
80 5.7888812 -0.3589635 2.7
81 5.4741865 -1.1803740 0.3
82 6.4508128 -2.4488802 0.3
83 -3.1939122 -2.4080958 5.4
84 5.7888812 -0.3589635 2.7
85 6.4508128 -2.4488802 0.3
86 -1.4732303 -3.9331403 4.9
87 -3.1939122 -2.4080958 5.4
88 6.4508128 -2.4488802 0.3
89 -3.4863074 0.3092904 6.8
90 -1.4732303 -3.9331403 4.9
91 6.4508128 -2.4488802 0.3
92 0.8019969 -2.2620347 7.2
93 -3.4863074 0.3092904 6.8
94 6.4508128 -2.4488802 0.3
95 -2.9970624 -0.1327280 8.0
96 0.8019969 -2.2620347 7.2
97 6.4508128 -2.4488802 0.3
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.