Plotting Lines and Points in 3D (2024)

31 views (last 30 days)

Show older comments

DJ V on 21 May 2024 at 14:40

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d

Commented: Voss on 21 May 2024 at 18:40

Accepted Answer: Voss

I need to learn how to plot lines and points in 3D. Can someone please provide an example in Matlab? Thank you.

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Voss on 21 May 2024 at 14:42

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#answer_1461106

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#answer_1461106

Open in MATLAB Online

A = [1 -3 7];

B = [0 2 -6];

C = [0.5 -1 5];

% plot a line from A to B

v = [A; B];

plot3(v(:,1),v(:,2),v(:,3))

box on

grid on

xlabel('x')

ylabel('y')

zlabel('z')

% plot the point C

hold on

plot3(C(1),C(2),C(3),'o')

Plotting Lines and Points in 3D (3)

8 Comments

Show 6 older commentsHide 6 older comments

DJ V on 21 May 2024 at 16:50

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167881

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167881

Edited: Voss on 21 May 2024 at 16:59

Open in MATLAB Online

Thank you for troubling to answer: I come up with the following trying to create a drawing, but two of the lines aren't being shown. The ones that go to -1 on the Y axis. Can this be fixed to include the -1 on the Y axis? Is there a way to control the magnitude of the box that is being turned on? Is there a way to control the dimensions of the box that is turned on? Thanks.

A1 = [0 0 0];

A2 = [1 1 2];

A3 = [-1 1 2];

A4 = [1 -1 2];

A5 = [-1 -1 2];

% plot a line from A1 to AN

v = [A1; A2];

plot3(v(:,1),v(:,2),v(:,3))

box on

hold on

v = [A1; A3];

plot3(v(:,1),v(:,2),v(:,3))

hold on

v = [A1, A4];

plot3(v(:,1),v(:,2),v(:,3))

hold on

v = [A1, A5];

plot3(v(:,1),v(:,2),v(:,3))

hold on

box on

grid on

Voss on 21 May 2024 at 16:58

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167886

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167886

Open in MATLAB Online

You're welcome!

The problem with the plots involving A4 and A5 is that you're horizontally concatenating instead of vertically concatenating, which makes v 1x6 instead of 2x3. When v is 1x6, doing plot3(v(:,1),v(:,2),v(:,3)) plots a single point instead of two points with a line in between.

A1 = [0 0 0];

A2 = [1 1 2];

A3 = [-1 1 2];

A4 = [1 -1 2];

A5 = [-1 -1 2];

% plot a line from A1 to AN

v = [A1; A2];

plot3(v(:,1),v(:,2),v(:,3))

hold on

v = [A1; A3];

plot3(v(:,1),v(:,2),v(:,3))

v = [A1; A4];

% ^ semicolon (not comma)

plot3(v(:,1),v(:,2),v(:,3))

v = [A1; A5];

% ^ semicolon (not comma)

plot3(v(:,1),v(:,2),v(:,3))

box on

grid on

You can control the axes limits (and thus the box around the axes) using xlim, ylim, and zlim, e.g.:

ylim([-1 2])

Plotting Lines and Points in 3D (6)

DJ V on 21 May 2024 at 17:09

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167896

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167896

Thank you very much!

Voss on 21 May 2024 at 17:17

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167911

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167911

You're welcome! Any questions, let me know. Otherwise, please "Accept" this answer. Thanks!

DJ V on 21 May 2024 at 18:01

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167981

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167981

Is there any command I can give to get MATLAB to draw this thing to scale? Thank you.

Voss on 21 May 2024 at 18:08

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167991

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3167991

Open in MATLAB Online

axis equal

Plotting Lines and Points in 3D (11)

DJ V on 21 May 2024 at 18:29

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3168011

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3168011

The man with all the answers!

Voss on 21 May 2024 at 18:40

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3168021

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2121111-plotting-lines-and-points-in-3d#comment_3168021

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsSurfaces, Volumes, and PolygonsSurface and Mesh Plots

Find more on Surface and Mesh Plots in Help Center and File Exchange

Tags

  • plot
  • 3d
  • matlab

Products

  • MATLAB

Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Plotting Lines and Points in 3D (14)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Plotting Lines and Points in 3D (2024)

FAQs

Plotting Lines and Points in 3D? ›

In the same way that we plot points in two-dimensional coordinate space by moving out along the x-axis to our x value, and then moving parallel to the y-axis until we find our point, in three-dimensional space we'll move along the x-axis, then parallel to the y-axis, then parallel to the z-axis until we arrive at our ...

How do you plot points on a 3D graph? ›

That is, to plot a point (x, y, z) in three dimensions, we follow these steps: Locate x on the x-axis. From that point, moving parallel to the y-axis, move y units. From that point, moving parallel to the z-axis, move z units; this is your point.

How do you plot a line with points? ›

To graph a linear equation by plotting points, you can use the intercepts as two of your three points. Find the two intercepts, and then a third point to ensure accuracy, and draw the line. This method is often the quickest way to graph a line.

How do we represent a point in 3D? ›

In the Cartesian form in the three-dimensional geometry, the representation is done using three coordinates: x-axis, y-axis, and z-axis. So the coordinates in three-dimensional geometry are x, y, z. The point of x value is abscissa, the y value is known as ordinate, and the z value is known as applicate.

What are the steps to plotting points? ›

Step 1: Identify the point in question, (x,y). Step 2: Determine its x-coordinate, which will be the horizontal distance from the origin. Step 3: Determine its y-coordinate, which will be the vertical distance from the origin. Step 4: Plot or label the point (depending on what the question is asking).

How to write 3D coordinates? ›

In two dimensions, we describe a point in the plane with the coordinates (x,y) . Each coordinate describes how the point aligns with the corresponding axis. In three dimensions, a new coordinate, z , is appended to indicate alignment with the z -axis: (x,y,z) ( x , y , z ) .

How do you graph a line based on points? ›

Graphing a Line Using the Slope and Y-Intercept
  1. Find the y-intercept = b of the equation y = mx + b.
  2. Plot the y-intercept. The point will be (0, b).
  3. Find the slope=m of the equation y = mx + b.
  4. Make a single step, using the rise and run from the slope. ...
  5. Connect those two points with your line.

What is the formula for plotting a line? ›

To graph an equation using the slope and y-intercept, 1) Write the equation in the form y = mx + b to find the slope m and the y-intercept (0, b). 2) Next, plot the y-intercept. 3) From the y-intercept, move up or down and left or right, depending on whether the slope is positive or negative.

How to find coordinates of 3D shapes? ›

Locate the point “x” on the X-axis. From the point x, moving parallel to the Y-axis, locate the point “y”. Similarly, from the determined point, moving parallel to the Z-axis, locate the point “z”. This is the final coordinate point in the three-dimensional plane, which we are looking for.

How to plot a point in 3D? ›

In the same way that we plot points in two-dimensional coordinate space by moving out along the x-axis to our x value, and then moving parallel to the y-axis until we find our point, in three-dimensional space we'll move along the x-axis, then parallel to the y-axis, then parallel to the z-axis until we arrive at our ...

What is the formula for 3D point? ›

Ans. In the three-dimensional coordinate system, the coordinates of a point A are represented as A (x, y, z). The point exists in an XYZ plane where x, y, and z represent the distance of point A from the Origin in X, Y, and Z coordinate axes, respectively. PQ = d = √ [(x2 – x1)2 + (y2 – y1)2 + (z2 – z1)2].

What is the formula for the line in 3D geometry? ›

3D Lines Formulas
NameFormula
Vector Formr = a + λ d
Parametric Formx = x₀ + λ a, y = y₀ + λ b, z = z₀ + λ c
Shortest Distance Between Skew Lines(Formula varies depending on specific approach)
Equation of a Line Through Two Pointsx = x₀ + t a, y = y₀ + t b, z = z₀ + t c
Apr 23, 2024

How do you plot 3 values on a graph? ›

The X and Y axes are used to plot two variables, and a third variable uses the Z axis to plot the contour levels. Contour levels are drawn as curved lines, and the areas between them can be colour-coded to indicate interpolated values.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Tish Haag

Last Updated:

Views: 6396

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tish Haag

Birthday: 1999-11-18

Address: 30256 Tara Expressway, Kutchburgh, VT 92892-0078

Phone: +4215847628708

Job: Internal Consulting Engineer

Hobby: Roller skating, Roller skating, Kayaking, Flying, Graffiti, Ghost hunting, scrapbook

Introduction: My name is Tish Haag, I am a excited, delightful, curious, beautiful, agreeable, enchanting, fancy person who loves writing and wants to share my knowledge and understanding with you.