Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Plotting a straight line in a 3D plot

730 views
Skip to first unread message

kheimon

unread,
Sep 7, 2007, 2:13:35 AM9/7/07
to
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.


DrMajorBob

unread,
Sep 8, 2007, 4:04:14 AM9/8/07
to
Clear[x, y, z]
zFunctions = {1 - x, y - 1};
endpts = {x, y, z} /.
First@Solve[
Equal @@ Flatten@{z, zFunctions}, {y, z}] /. {{x -> -5}, {x ->
5}};
Show[Plot3D[zFunctions, {x, -5, 5}, {y, -5, 5}],
Graphics3D[{Thickness[.01], Line@endpts}]]

or (the line all by itself):

Graphics3D[{Thickness[.01], Line@endpts}]

Bobby

--

DrMaj...@bigfoot.com

dimitris

unread,
Sep 8, 2007, 4:24:29 AM9/8/07
to

Show[Graphics3D[{{Red, Line[{{0, 0, 0}, {1, 1, 1}}]},{Blue, Line[{{1,
0, 1}, {0, 1/2, 1/2}}]}}], Axes -> True, AxesLabel -> {"x", "y", "z"}]

???

Dimitris


Jens-Peer Kuska

unread,
Sep 9, 2007, 6:08:01 AM9/9/07
to
Hi,

you mean ParametricPlot3D[] and

ParametricPlot3D[
{t,0,0},{t,0,-5,5}]

will plot the line.

Regards
Jens

Jean-Marc Gulliet

unread,
Sep 9, 2007, 6:23:22 AM9/9/07
to
kheimon wrote:

First, the given example will work better if written as follows (the
assignments = have been removed as well as the extra curly brackets),

Plot3D[{1 - x, y - 1}, {x, -5, 5}, {y, -5, 5}]

Second, to plot a line in 3D, one can use *Graphics3D* and *Line* as in

Graphics3D[Line[{{0, 0, 0}, {1, 1, 1}}]]

and one can combine a regular plot with a line with *Show*

Show[Plot3D[{1 - x, y - 1}, {x, -5, 5}, {y, -5, 5}],
Graphics3D[Line[{{0, 0, 0}, {0, 5, 5}}]]]

HTH,
--
Jean-Marc

0 new messages