Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plotting points in 3-D in Mathematica

  1. Sep 9, 2011 #1
    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
     
  2. jcsd
  3. Sep 9, 2011 #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: Sep 9, 2011
  4. Sep 9, 2011 #3


    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.
     
  5. Sep 9, 2011 #4
    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.
     
  6. Sep 9, 2011 #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
     

    Attached Files:

  7. Sep 9, 2011 #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.
     
  8. Sep 11, 2011 #7
    Dear Bill,

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

    Best Regards

    Take Care
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Plotting points in 3-D in Mathematica
Loading...