[Mathematica] Plotting a straight line in a 3D plot

In summary: There is no easy way to do the same. You would have to write a separate program to solve for the equation of a line with one pt(x,y,z) and makes angle p to x-axis and q to y axis.
  • #1
euthymos
3
0
Is there any way, in Mathematica, I can plot a straight line in a 3D plot environment?

For example: Plot3D[{{y = 1 - x, z = y - 1}}, {x, -5, 5}, {y, -5, 5}]

plots two surfaces, not their intersection (which is a straight line).

Thank you in advance.
 
Physics news on Phys.org
  • #2
You have to use mathematica to find the intersection before you can plot it.
 
  • #3
genneth said:
You have to use mathematica to find the intersection before you can plot it.

how? The intersection of that two surfaces is a straight line. There's nothing to find.
 
  • #4
Mathematica assumes you are asking it to plot two surfaces, namely y = 1 - x and z = y - 1. You should read the help file, which comes with a lot of examples. I suggest you to use a parametric plot instead.
 
  • #5
euthymos said:
how? The intersection of that two surfaces is a straight line. There's nothing to find.

It's obvious to you... but not to computer. After all, the equations could be degenerate, and probably other implicit assumptions that we're used to. In this case, ParametricPlot3D is your friend -- it will give you a line in 3D. However, you'll still have to find a parametric form of the line. I'm not sure how to do that in a nice way, such that there are no edge cases, for any 2 given planes.
 
  • #6
euthymos said:
how? The intersection of that two surfaces is a straight line. There's nothing to find.
The intersection of the two planes y= 1- x and z= y-1 can be written with x= 1- y and z= y-1: taking y itself as parameter, x= 1-t, y= t, z= t-1. That's what there is to find.
 
  • #7
Finally! I've converted the cartesian equations into parametric one and plotted with ParametricPlot3D.

ParametricPlot3D[{x = 1 - t, y = t, z = t - 1}, {t, -5, 5}]

Thanks a lot for you help! Thanks all!
 
  • #8
hello,
I am need to solve for a program that would give the equation of a line with one pt(x,y,z) and makes angle p to x-axis and q to y axis. I have written a program that is too long, Is there an easy way to do the same?
 

1. How do I plot a straight line in a 3D plot using Mathematica?

To plot a straight line in a 3D plot using Mathematica, you can use the ParametricPlot3D function. This function takes in two parameters, x and y, and a range of values for each parameter. You can then specify the equation for the straight line using the x and y parameters.

2. Can I add multiple straight lines to a 3D plot in Mathematica?

Yes, you can add multiple straight lines to a 3D plot in Mathematica by using the ParametricPlot3D function multiple times with different equations for each line. You can also use the Show function to combine multiple plots into one.

3. How can I change the color and style of the straight line in a 3D plot?

To change the color and style of the straight line in a 3D plot, you can use the PlotStyle option in the ParametricPlot3D function. This option allows you to specify the color, thickness, and other style elements of the line.

4. Is it possible to label the axes and add a title to a 3D plot in Mathematica?

Yes, it is possible to label the axes and add a title to a 3D plot in Mathematica. You can use the AxesLabel and PlotLabel options in the ParametricPlot3D function to specify the labels and title, respectively.

5. Can I export a 3D plot with the straight line to an image file in Mathematica?

Yes, you can export a 3D plot with the straight line to an image file in Mathematica. You can use the Export function and specify the desired image format to save the plot as an image file.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
201
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
722
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
830
Back
Top