Message Boards Message Boards

0
|
3979 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Plotting a line in 3 space

Posted 11 years ago
Hello everyone...

I've been exploring Mathematica (version 8) this afternoon and I was working with plots and various functionality. I usually like to find a basic thing to start with and then add notes to it and build it up with more and more detail. Then I save these so I can go back later in case I forget how to do something.

I wanted to plot a straight line in 3D. Just a simple line like you'd see in 2D ---- y = x (example below), but I want this line to extend out in 3-space. I tried to modify some of the examples in help, but they fail, and the error messages are just as cryptic as they have always been in the computer world.


Plot[x, {x, -3, 3}]
 




This is part of another goal and that is to plot random x, y, z data points about this line. If anyone has ideas about this as well that would be great, but the line is my main interest right now.

Thanks
POSTED BY: fizixx :)
4 Replies
Show[Graphics3D[Line[{{1, 1, -1}, {2, 2, 1}}]], Axes -> True]
POSTED BY: Frank Kampas
Hi,

>> This is part of another goal and that is to plot random x, y, z data points about this line.
>> If anyone has ideas about this as well that would be great, but the line is my main interest right now.

Given a line specified by end points ( {{1, 1, -1}, {2, 2, 1}} in your case),  
it is possible to define a frame using translations and rotations where line will coincide with one of the axis.
In this new frame line end points are {{0,0,0},{0,0,length}}
Placing random points  in the new frame is easy . I used a cylinder area to place points in:
 endpoints = {{0, 0, 0}, {0, 0, 1}};
 rad = 0.2;
 points = DeleteCases[
    Table[{RandomReal[{-rad, rad}], RandomReal[{-rad, rad}],
      RandomReal[{0, 1}]}, {i, 1,1000}], _?(#1[[1]]^2 + #1[[2]]^2 > rad^2 &)];
 Show[
 Graphics3D[{Thick, Line[endpoints]}],
 Graphics3D[{PointSize[Large], Yellow, Point[points]}],
 Graphics3D[{Opacity[0.1], Cylinder[endpoints, rad]}]
]
You might consider using Rotate[] and Translate[] functions for Graphics3D[] to transform your line into new frame,
then generate points with above method, and finally inverse-transform everything (line and generated points) back to the old frame.

Probably there is a better way, but you can give this a try.

I.M.
POSTED BY: Ivan Morozov
Posted 11 years ago
Frank ----- THANK YOU!!
POSTED BY: fizixx :)
Posted 11 years ago
Ivan.....

That is great. I will follow along with your suggestions for Rotate[] and the rest. Thanks very much!!!
POSTED BY: fizixx :)
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract