Plotting points in 3-D in Mathematica

In summary: Flatten call, then the plot command would also display at the bottom right hand corner. With 6.0, this behavior changed so that the plot command now takes precedence and will not display anything else.
  • #1
sedat
15
0
Hello friends;

The points in the source code is supposed to be drawn in 3-D,

S in source code means points in cartesian cordinate (X-Y-Z) respectively.

I am supposed to draw the points in 3-D graph.

Please friends, help me do this.

The source Code is below

a2 = 90; Rz1 = {{Cos[a1 Degree], -Sin[a1
Degree], 0}, {Sin[a1 Degree], Cos[a1 Degree], 0}, {0, 0, 1}};
Rx1 = {{1, 0, 0}, {0, Cos[a2 Degree], -Sin[a2 Degree]}, {0, Sin[a2 Degree],
Cos[a2 Degree]}};
Rz2 = {{Cos[a3 Degree], -Sin[a3 Degree], 0}, {Sin[a3
Degree], Cos[a3 Degree], 0}, {0, 0, 1}};
U = {{1}, {0}, {0}};
S = For[a1 = 0Degree, a1 < 360Degree, a1 += 10Degree,
For[a3 = 0Degree, a3 < 180Degree,
a3 += 10Degree, Print[C = Rz1.Rx1.Rz2.U // N]]]

Thank you

Best Regads
 
Physics news on Phys.org
  • #2
There are several different problems with your code.
1: Your For loops have a1 and a2 in Degrees, but then in Rz1,Rx1,Rz2 you have another Degree so that you are going to end up with 0 Degree squared, 10 Degree squared, etc.

2: using = versus := is a source of confusion for new users.

3: For is not a function that gives you all the results calculated inside the loop, Table does that.

I think this is closer to what you are trying to accomplish.

a2 = 90; Rz1 := {{Cos[a1 Degree], -Sin[a1 Degree], 0}, {Sin[a1 Degree], Cos[a1 Degree], 0}, {0, 0, 1}};
Rx1 := {{1, 0, 0}, {0, Cos[a2 Degree], -Sin[a2 Degree]}, {0, Sin[a2 Degree], Cos[a2 Degree]}};
Rz2 := {{Cos[a3 Degree], -Sin[a3 Degree], 0}, {Sin[a3 Degree], Cos[a3 Degree], 0}, {0, 0, 1}};
U = {{1}, {0}, {0}};
S = Flatten[Table[Flatten[N[Rz1.Rx1.Rz2.U]], {a1, 0, 350, 10}, {a3, 0, 170, 10}],1];
ListPointPlot3D

or if you absolutely positively must use For then

S = Reap[For[a1 = 0, a1 < 360, a1 += 10, For[a3 = 0, a3 < 180, a3 += 10, Sow[Rz1.Rx1.Rz2.U // N // Flatten]]]][[2, 1]]

You could alternatively take the Degree out of your Rz1, Rx1 and Rz2 initializations and put the Degree back into your For or Table.

Study this character by character to see exactly the details of what I have changed. Then try doing or undoing each of those changes and study how the result changes until you understand exactly what is happening.

There are always at least a dozen different ways of writing anything in Mathematica, at least several of which are completely incomprehensible.
 
Last edited:
  • #3
Bill Simpson said:
There are several different problems with your code.
1: Your For loops have a1 and a2 in Degrees, but then in Rz1,Rx1,Rz2 you have another Degree so that you are going to end up with 0 Degree squared, 10 Degree squared, etc.

2: using = versus := is a source of confusion for new users.

3: For is not a function that gives you all the results calculated inside the loop, Table does that.

I think this is closer to what you are trying to accomplish.

a2 = 90; Rz1 := {{Cos[a1 Degree], -Sin[a1 Degree], 0}, {Sin[a1 Degree], Cos[a1 Degree], 0}, {0, 0, 1}};
Rx1 := {{1, 0, 0}, {0, Cos[a2 Degree], -Sin[a2 Degree]}, {0, Sin[a2 Degree], Cos[a2 Degree]}};
Rz2 := {{Cos[a3 Degree], -Sin[a3 Degree], 0}, {Sin[a3 Degree], Cos[a3 Degree], 0}, {0, 0, 1}};
U = {{1}, {0}, {0}};
S = Flatten[Table[Flatten[N[Rz1.Rx1.Rz2.U]], {a1, 0, 350, 10}, {a3, 0, 170, 10}],1];
ListPointPlot3D

or if you absolutely positively must use For then

S = Reap[For[a1 = 0, a1 < 360, a1 += 10, For[a3 = 0, a3 < 180, a3 += 10, Sow[Rz1.Rx1.Rz2.U // N // Flatten]]]][[2, 1]]

You could alternatively take the Degree out of your Rz1, Rx1 and Rz2 initializations and put the Degree back into your For or Table.

Study this character by character to see exactly the details of what I have changed. Then try doing or undoing each of those changes and study how the result changes until you understand exactly what is happening.

There are always at least a dozen different ways of writing anything in Mathematica, at least several of which are completely incomprehensible.


well...my mistake is understood, your code works properly, but I cannot see 3D graph from your code in the screen, it is possible to result from my version of Mathematica?

Meanwhile, there was also a problem on my last thesis in last year since the same logic mistake was valid, I mean Degree squared I am going to revise it, most probably the view of 3D graph will change.
 
  • #4
sedat said:
well...my mistake is understood, your code works properly, but I cannot see 3D graph from your code in the screen, it is possible to result from my version of Mathematica?

Meanwhile, there was also a problem on my last thesis in last year since the same logic mistake was valid, I mean Degree squared I am going to revise it, most probably the view of 3D graph will change.

In versions before 6.0 Plot commands would display the plot in addition to anything else it did. In versions 6.0 and after you may have to Print[Plot[...]] or do other things, but I cannot say because I do not know what version you have or what the rest of your notebook contains.

In Mathematica Degree is nothing more than a name for a constant Pi/180. This is not like FORTRAN or C where you might think you are telling Mathematica something about the variable x when you say x Degree.

As always, if you can show the content of a notebook with all the detail needed for someone to understand your problem and with no more detail to take their time to understand then others are more likely to help and more likely to provide the correct answer.

I always suggest carefully testing and checking the result of any Mathematica calculation to verify that the results are correct. If all your values in your thesis plot were multiplied by Pi/180 I would think you would have realized there was something very wrong.
 
  • #5
Dear Bill,

Eventually, I could be able to verify the answers with CAD and excel. it is OK.

Sure that I know unit of the angle is radian in mathematica just like excel, so need to multiply Pi/180 but really it is hard to understand the algorithm of mathematica for me.

I am about to complete my thesis :)

I kindly request from you to check FOR loop the attached file that we constructed in last year.

I wonder if there is logic mistake in FOR loop or not. I mean the problem of the squared degree...it is Ok in that code? I am sure it is OK but it is much more better that you will check, by the way, my version is 4.2 it is very old :) I will manage it in such way.

Thanks for your kind understanding.

Please see the attached mathematica file.

Best Regards
 

Attachments

  • last year.nb
    17.8 KB · Views: 534
  • #6
I thought your name seemed familiar and now when I see the notebook we worked on I remember how much work we did to get it working.

There is a lot of material in the notebook, so it is difficult for me to be certain that there are no hidden errors remaining.

When I showed ListPointPlot3D in my reply to you today I did not realize you had MMA version 4.2. ListPointPlot3D was not added until Mathematica 6.0. You could make a plot similar to ListPointPlot3D in version 4.2 by using something similar to what I showed you in your notebook last year.

S = Flatten[Table[Flatten[N[Rz1.Rx1.Rz2.U]], {a1, 0, 350, 10}, {a3, 0, 170, 10}],1];
Show[Graphics3D[Map[Point[#] &, S]]]

Try that with your new data and see if it gives you a plot. Then we can adjust it if needed.
 
  • #7
Dear Bill,

I would like to thank you for your support, it is a very clear explanation. Thesis is totally OK now :)

Best Regards

Take Care
 

Related to Plotting points in 3-D in Mathematica

1. How do I plot points in 3-D in Mathematica?

To plot points in 3-D in Mathematica, you can use the "ListPointPlot3D" function. This function takes in a list of coordinates for the points and creates a 3-D scatter plot. You can also use the "Graphics3D" function to manually specify the coordinates and style of the points.

2. How do I add labels and axes to my 3-D plot?

You can add labels and axes to your 3-D plot by using the "AxesLabel" option in the "ListPointPlot3D" or "Graphics3D" functions. You can specify the labels for the x, y, and z axes as well as the overall plot title. You can also use the "AxesStyle" option to customize the appearance of the axes.

3. Can I change the color and shape of the plotted points?

Yes, you can change the color and shape of the plotted points by using the "PlotStyle" option in the "ListPointPlot3D" or "Graphics3D" functions. You can specify the color, shape, and size of the points using a variety of formatting options. Additionally, you can use the "PlotMarkers" option to add custom symbols or shapes to the points.

4. How can I add a line or curve to my 3-D plot?

To add a line or curve to your 3-D plot, you can use the "ListLinePlot3D" or "ParametricPlot3D" functions. These functions allow you to specify the coordinates and style of the line or curve and add it to your existing 3-D plot. You can also use the "Show" function to combine multiple plots into one figure.

5. Is it possible to rotate and manipulate the 3-D plot?

Yes, you can rotate and manipulate the 3-D plot by using the "Manipulate" function. This function allows you to interactively change the viewing angle and perspective of the plot. You can also use the "ViewPoint" option in the "ListPointPlot3D" or "Graphics3D" functions to specify the initial viewing angle.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
913
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
913
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
11
Views
780
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
Replies
30
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
Back
Top