using tikz to plot points and draw lines in 3d

Introduction

TikZ is probably the most circuitous and powerful tool to create graphic elements in 50aTeastwardX. Starting with a uncomplicated example, this article introduces some bones concepts: drawing lines, dots, curves, circles, rectangles etc.

Firstly, load the tikz package past including the line \usepackage{tikz} in the preamble of your certificate, then draw a graphic using the tikzpicture environment.

                        \documentclass            {article}            \usepackage            {tikz}            \begin            {document}            \begin            {tikzpicture}            \draw            [greyness, thick]            (-1,2) -- (ii,-iv);            \depict            [grayness, thick]            (-one,-1) -- (2,two);            \filldraw            [black]            (0,0) circle (2pt) node[anchor=west]{Intersection point};            \cease            {tikzpicture}            \cease            {document}          

 Open up this case in Overleaf

This instance produces the post-obit output:

OLV2tikz1.png

In this example two lines and one point are drawn. To add together a line the command \draw[gray, thick] defines a graphic element whose colour is grey and with a thick stroke. The line is actually defined by it'due south 2 endpoints, (-1,two) and (two,-4), joined past --.

The bespeak is actually a circumvolve drawn past \filldraw[black], this command will not only draw the circle just fill up information technology using black. In this command the heart bespeak (0,0) and the radius (2pt) are declared. Next to the point is a node, which is really a box containing the text intersection point, and anchored at the westward of the indicate.

Information technology'due south of import to notice the semicolon ; used at the cease of each draw command.

Note: The tikzfigure surroundings tin can be enclosed inside a effigy or similar environment. See the Inserting Images article for more than information on this topic.

Basic elements: points, lines and paths

In this section nosotros provide some examples showing how to create some basic graphic elements which can exist combined to create more elaborate figures.

                        \documentclass            {article}            \usepackage            {tikz}            \begin            {document}            \brainstorm            {tikzpicture}            \describe            (-2,0) -- (2,0);            \filldraw            [gray] (0,0) circle (2pt);            \draw            (-2,-2) .. controls (0,0) .. (two,-2);            \draw            (-2,2) .. controls (-1,0) and (1,0) .. (2,2);            \end            {tikzpicture}            \end            {document}          

 Open this example in Overleaf

This instance produces the following output:

OLV2tikz2.png

There are iii basic commands in this case:

  • \draw (-2,0) -- (ii,0); : This defines a line whose endpoint are (-2,0) and (2,0).
  • \filldraw [gray] (0,0) circumvolve (2pt); : The indicate is created equally a very minor gray circle centred at (0,0) and whose radius is (2pt). The \filldraw command is used to depict elements and make full them with a specific colour. See the next section for more examples.
  • \depict (-two,2) .. controls (-1,0) and (ane,0) .. (two,2); : Draws a Bézier curve. There are four points defining it: (-2,two) and (2,two) are its endpoints, (-1,0) and (1,0) are command points that determine "how curved" it is. You tin recall of these 2 points every bit "attractor points".

Basic geometric shapes: Circles, ellipses and polygons

Geometric figures tin can be synthetic from simpler elements so let's start with circles, ellipses and arcs.

                        \documentclass            {commodity}            \usepackage            {tikz}            \begin            {certificate}            \begin            {tikzpicture}            \filldraw            [color=ruby!60, fill up=red!5, very thick](-1,0) circle (1.five);            \fill            [bluish!fifty]            (2.5,0) ellipse (i.5 and 0.v);            \draw            [ultra thick, ->]            (six.5,0) arc (0:220:1);            \end            {tikzpicture}            \end            {document}          

 Open this case in Overleaf

This example produces the following output:

TikzEx3.png

  • \filldraw[color=scarlet!60, make full=red!five, very thick](-i,0) circle (1.v); : This command was used in the previous department to draw a point, but in this instance there are some boosted parameters inside the brackets. These are explained below:
    • color=red!60 : The colour of the ring around the circle is set to 60% red (lighter than "pure" red). See the reference guide for a listing of the default colours available in LaTe10; besides, see Using colours in LaTeX to learn how to create your own colours.
    • fill=red!five : The circle is filled with an even lighter shade of blood-red.
    • very thick : This parameter defines the thickness of the stroke. See the reference guide for a consummate list of values.
  • \fill up[blue!50] (2.v,0) ellipse (ane.5 and 0.v); : To create an ellipse you provide a center point (2.5,0), and two radii: horizontal and vertical (one.5 and 0.v respectively). Besides notice the control fill instead of draw or filldraw, this is because, in this case, there'due south no need to control outer and inner colours.
  • \describe[ultra thick, ->] (half dozen.five,0) arc (0:220:ane); : This control will draw an arc starting at (half dozen.5,0). The extra parameter -> indicates that the arc volition have an arrow at the finish. In addition to the starting bespeak you lot must provide three boosted values: the starting and ending angles, and the radius; here, these three parameter values are provided in the format (0:220:1).

In addition to curved geometric shapes you lot can as well create elements that use direct lines, using a similar syntax:

                        \documentclass            {article}            \usepackage            {tikz}            \brainstorm            {certificate}            \begin            {tikzpicture}            \draw            [blueish, very thick]            (0,0) rectangle (3,2);            \draw            [orange, ultra thick]            (4,0) -- (half-dozen,0) -- (five.7,2) -- bicycle;            \end            {tikzpicture}            \end            {document}          

 Open this example in Overleaf

This instance produces the following output:

OLV2tikz4.png

  • \draw[blue, very thick] (0,0) rectangle (3,two); : Rectangles are created by the special command rectangle. You have to provide two points, the starting time one is where the "pencil" begins to draw the rectangle and the 2nd one is the diagonally opposite corner bespeak.
  • \draw[orange, ultra thick] (iv,0) -- (6,0) -- (five.vii,2) -- cycle; : To draw a polygon we draw a airtight path of straight lines: a line from (4,0) to (half dozen,0) and a line from (6,0) to (5.7,2). The cycle pedagogy means that the beginning and end points should coincide to create a "closed" path (shape), which results in construction of the last line segment.

Diagrams

Nodes are probably the most versatile elements in TikZ. Nosotros've already used one node in the introduction—to add some text to the figure. The next example uses nodes to create a diagram.

                        \documentclass            {commodity}            \usepackage            {tikz}            \usetikzlibrary            {positioning}            \begin            {document}            \brainstorm            {tikzpicture}[ roundnode/.style={circumvolve, draw=light-green!60, make full=green!5, very thick, minimum size=7mm}, squarednode/.style={rectangle, draw=red!lx, fill up=red!v, very thick, minimum size=5mm}, ]            %Nodes            \node            [squarednode]            (maintopic)            {2};            \node            [roundnode]            (uppercircle)       [above=of maintopic]            {1};            \node            [squarednode]            (rightsquare)       [right=of maintopic]            {3};            \node            [roundnode]            (lowercircle)       [below=of maintopic]            {four};            %Lines            \draw            [->]            (uppercircle.south) -- (maintopic.northward);            \draw            [->]            (maintopic.east) -- (rightsquare.west);            \describe            [->]            (rightsquare.south) .. controls +(down:7mm) and +(correct:7mm) .. (lowercircle.e);            \end            {tikzpicture}            \end            {document}          

 Open this instance in Overleaf

This example produces the following output:

OLV2tikz5.png

There are essentially iii commands in this effigy: A node definition, a node annunciation and lines that join two nodes.

  • roundnode/.style={circumvolve, describe=dark-green!60, fill=green!5, very thick, minimum size=7mm} : Passed as a parameter to the tikzpicture environment. It defines a node that volition be referenced as roundnode: this node volition exist a circumvolve whose outer band will be drawn using the color light-green!60 and will be filled using green!five. The stroke volition be very thick and its minimum size is 7mm. The line beneath this defines a second rectangle-shaped node called squarednode, using similar parameters.
  • \node[squarednode] (maintopic) {two}; : This will create a squarednode, as defined in the previous command. This node will have an id of maintopic and volition contain the number ii. If you get out an empty space inside the braces no text will be displayed.
  • [to a higher place=of maintopic] : Detect that all but the beginning node have an boosted parameter that determines its position relative to other nodes. For instance, [to a higher place=of maintopic] means that this node should appear in a higher place the node named maintopic. For this positioning system to piece of work y'all have to add \usetikzlibrary{positioning} to your preamble. Without the positioning library, you can use the syntax above of=maintopic instead, but the positioning syntax is more than flexible and powerful: you lot can extend it to write above=3cm of maintopic i.due east. control the bodily distance from maintopic.
  • \draw[->] (uppercircle.south) -- (maintopic.northward); : An pointer-like straight line will be drawn. The syntax has been already explained in the basic elements section. The merely difference is the manner in which we write the endpoints of the line: past referencing a node (this is why we named them) and a position relative to the node.

Reference Guide

Possible color and thickness parameters in the tikz bundle:

parameter values picture
colour white, black, scarlet, greenish, blue, cyan, magenta, yellow BasicColours.png
thickness ultra sparse, very thin, thin, thick, very thick, ultra thick Thickness.png

More colours may exist available in your FiftyaTeastwardTen distribution. Run across Using colours in LaTeX

Further reading

For more information come across:

  • Using colours in LaTeX
  • Pgfplots package
  • Inserting Images
  • Lists of tables and figures
  • Positioning images and tables
  • Drawing diagrams directly in LaTeX
  • The TikZ and PGF Packages Manual
  • TikZ and PGF examples at TeXample.net

orozcotair1956.blogspot.com

Source: https://www.overleaf.com/learn/latex/TikZ_package

0 Response to "using tikz to plot points and draw lines in 3d"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel