Plotting points in 3-D in Mathematica

Click For Summary

Discussion Overview

The discussion revolves around plotting points in 3-D using Mathematica. Participants explore issues related to the source code provided for generating a 3-D graph, including syntax and function usage, while also addressing potential version-related limitations of Mathematica.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help with a source code intended to plot points in 3-D, specifying that the points are in Cartesian coordinates.
  • Another participant identifies multiple issues with the original code, including the use of degrees in the For loops and the difference between using = and :=, suggesting that Table may be more appropriate than For for generating results.
  • There is a suggestion to modify the code to ensure proper plotting, including the use of ListPointPlot3D and alternatives for older versions of Mathematica.
  • A participant expresses confusion about not being able to see the 3-D graph and questions whether it could be due to the version of Mathematica they are using.
  • Concerns are raised about the understanding of angle units in Mathematica, with references to the need for converting degrees to radians.
  • Another participant recalls past collaboration on a notebook and notes that ListPointPlot3D is not available in Mathematica version 4.2, suggesting a workaround using Graphics3D and Point.
  • One participant expresses gratitude for the support received and indicates that their thesis is now complete.

Areas of Agreement / Disagreement

Participants generally agree on the issues present in the original code and the need for corrections, but there is no consensus on the best approach for plotting in older versions of Mathematica. The discussion remains unresolved regarding the specific limitations of the participant's version and how it affects plotting capabilities.

Contextual Notes

Limitations include the potential confusion arising from the use of degrees versus radians, the differences in function behavior between Mathematica versions, and the specific capabilities of version 4.2 compared to later versions.

Who May Find This Useful

Users of Mathematica, particularly those working with 3-D plotting and those using older versions of the software, may find this discussion relevant.

sedat
Messages
15
Reaction score
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
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:
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.
 
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.
 
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

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.
 
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K