TikZ drawing of a red tractor in 3d
- User
TikZ drawing of a red tractor in 3d
Assistant
Of course! Here is the TikZ code to generate a 3D-style drawing of a red tractor.
This code uses the
tikz-3dplotpackage to create an isometric perspective, which gives the illusion of three dimensions. The tractor is built from basic shapes like cuboids (for the body), cylinders (for the wheels and exhaust), and polygons.I've added extensive comments to the code so you can understand how each part is constructed and easily customize it.
Final Result
Here is what the code will produce: [image: TikZ 3D Tractor] open
TikZ Code
To use this code, you'll need a LaTeX distribution with the
tikzandtikz-3dplotpackages installed.\documentclass[tikz, border=5mm]{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} % A command for drawing a cylinder in 3D perspective % #1: x-pos, #2: y-pos, #3: z-pos (center of bottom face) % #4: radius, #5: height \newcommand{\drawCylinder}[5]{ \scope[shift={(#1,#2,#3)}] % Draw back face \draw[fill=white, very thin] (0,0,0) -- ++(0,#4,0) arc (90:270:#4) -- cycle; % Draw main body \draw[fill=white, very thin] (0,#4,0) -- (0,#4,#5) arc (90:-90:#4) -- (0,-#4,#5) -- cycle; % Draw front face \draw[fill=white] (0,0,#5) circle (#4); \endscope } \begin{document} \begin{tikzpicture} % Set the 3D viewing angle (rotation around z, then rotation in x-y plane) \tdplotsetmaincoords{70}{110} % Define colors for easier customization \colorlet{TractorRed}{red!80!black} \colorlet{TireBlack}{gray!20!black} \colorlet{RimGray}{gray!60!white} \colorlet{WindowBlue}{blue!20} \colorlet{ExhaustGray}{gray!40!black} \colorlet{SmokeGray}{gray!50} % Use a scope to apply the 3D perspective to all elements inside \begin{scope}[tdplot_main_coords, line join=round, line cap=round] % --- Ground Shadow --- % A simple ellipse to ground the tractor \fill[black, opacity=0.2, transform canvas={yshift=-0.5mm}] (2.5, 0, 0) ellipse (3.5 and 1.5); % --- Back Wheels --- \def\Rback{1.5} % Radius of back wheels \def\Wback{0.7} % Width of back wheels \def\Yaxle{2.2} % Distance between back wheels center % Far Back Wheel \begin{scope}[shift={(0, -\Yaxle/2, \Rback)}] % Tire \fill[TireBlack] (0,0,0) circle (\Rback); \foreach \angle in {0,20,...,340} { \draw[TireBlack, very thick] (\angle:\Rback*0.8) -- (\angle:\Rback); } \fill[TireBlack, opacity=0.4] (0,0,0) circle (\Rback); % Rim \fill[RimGray] (0,0,0) circle (\Rback*0.5); \fill[white] (0,0,0) circle (\Rback*0.45); \fill[RimGray] (0,0,0) circle (\Rback*0.1); \end{scope} % --- Main Body / Chassis --- \def\BodyL{3.5} % Length \def\BodyW{1.8} % Width \def\BodyH{1.2} % Height \def\BodyZ{1.2} % Z-position (height off ground) % Main block \filldraw[TractorRed, draw=black] (-\BodyL/2, -\BodyW/2, \BodyZ) -- (\BodyL/2, -\BodyW/2, \BodyZ) -- (\BodyL/2, \BodyW/2, \BodyZ) -- (-\BodyL/2, \BodyW/2, \BodyZ) -- cycle; % Bottom face (mostly hidden) \filldraw[TractorRed, draw=black] (-\BodyL/2, \BodyW/2, \BodyZ) -- (\BodyL/2, \BodyW/2, \BodyZ) -- (\BodyL/2, \BodyW/2, \BodyZ+\BodyH) -- (-\BodyL/2, \BodyW/2, \BodyZ+\BodyH) -- cycle; % Side face \filldraw[TractorRed, draw=black] (\BodyL/2, -\BodyW/2, \BodyZ) -- (\BodyL/2, \BodyW/2, \BodyZ) -- (\BodyL/2, \BodyW/2, \BodyZ+\BodyH) -- (\BodyL/2, -\BodyW/2, \BodyZ+\BodyH) -- cycle; % Front face \filldraw[TractorRed, draw=black] (-\BodyL/2, -\BodyW/2, \BodyZ+\BodyH) -- (\BodyL/2, -\BodyW/2, \BodyZ+\BodyH) -- (\BodyL/2, \BodyW/2, \BodyZ+\BodyH) -- (-\BodyL/2, \BodyW/2, \BodyZ+\BodyH) -- cycle; % Top face % --- Front Wheels --- \def\Rfront{0.8} % Radius of front wheels \def\Wfront{0.4} % Width of front wheels \def\YaxleFront{1.8} % Distance between front wheels \def\Xfront{3.0} % X position of front axle % Far Front Wheel \begin{scope}[shift={(\Xfront, -\YaxleFront/2, \Rfront)}] \fill[TireBlack] (0,0,0) circle (\Rfront); \fill[RimGray] (0,0,0) circle (\Rfront*0.5); \fill[white] (0,0,0) circle (\Rfront*0.45); \fill[RimGray] (0,0,0) circle (\Rfront*0.1); \end{scope} % Near Front Wheel \begin{scope}[shift={(\Xfront, \YaxleFront/2, \Rfront)}] \fill[TireBlack] (0,0,0) circle (\Rfront); \fill[RimGray] (0,0,0) circle (\Rfront*0.5); \fill[white] (0,0,0) circle (\Rfront*0.45); \fill[RimGray] (0,0,0) circle (\Rfront*0.1); \end{scope} % --- Cabin --- \def\CabL{1.5} \def\CabW{1.6} \def\CabH{1.4} \def\CabX{-0.5} \def\CabZ{\BodyZ+\BodyH} % Cabin Frame and Windows \coordinate (CB1) at (\CabX-\CabL/2, \CabW/2, \CabZ); \coordinate (CB2) at (\CabX+\CabL/2, \CabW/2, \CabZ); \coordinate (CB3) at (\CabX+\CabL/2, \CabW/2, \CabZ+\CabH); \coordinate (CB4) at (\CabX-\CabL/2, \CabW/2, \CabZ+\CabH); \coordinate (CF1) at (\CabX+\CabL/2, -\CabW/2, \CabZ); \coordinate (CF2) at (\CabX+\CabL/2, \CabW/2, \CabZ); \coordinate (CF3) at (\CabX+\CabL/2, \CabW/2, \CabZ+\CabH); \coordinate (CF4) at (\CabX+\CabL/2, -\CabW/2, \CabZ+\CabH); % Windows (drawn first to be behind the frame) \fill[WindowBlue, opacity=0.6] (CB1) -- (CB2) -- (CB3) -- (CB4) -- cycle; % Side window \fill[WindowBlue, opacity=0.6] (CF1) -- (CF2) -- (CF3) -- (CF4) -- cycle; % Front window % Cabin Frame \draw[TractorRed, very thick] (CB1) -- (CB4) -- (CB3) -- (CB2); \draw[TractorRed, very thick] (CF4) -- (CF3); \draw[TractorRed, very thick] (\CabX-\CabL/2, -\CabW/2, \CabZ+\CabH) -- (CB4); \draw[TractorRed, very thick] (\CabX+\CabL/2, -\CabW/2, \CabZ+\CabH) -- (CF4); \draw[TractorRed, very thick] (\CabX-\CabL/2, -\CabW/2, \CabZ+\CabH) -- (\CabX+\CabL/2, -\CabW/2, \CabZ+\CabH); % Top back edge % Steering wheel inside cabin \draw[black, thick] (\CabX, \CabW/2-0.2, \CabZ+0.4) circle (0.3); \draw[black, thick] (\CabX, \CabW/2-0.2, \CabZ+0.4) -- ++(-45:0.3); % --- Near Back Wheel --- % Drawn last to be in front of the body \begin{scope}[shift={(0, \Yaxle/2, \Rback)}] % Tire \fill[TireBlack] (0,0,0) circle (\Rback); \foreach \angle in {0,20,...,340} { \draw[TireBlack, very thick] (\angle:\Rback*0.8) -- (\angle:\Rback); } % Rim \fill[RimGray] (0,0,0) circle (\Rback*0.5); \fill[white] (0,0,0) circle (\Rback*0.45); \fill[RimGray] (0,0,0) circle (\Rback*0.1); \end{scope} % --- Exhaust Pipe --- \def\ExhaustX{1.8} \def\ExhaustY{1.0} \def\ExhaustZ{\BodyZ+\BodyH} \def\ExhaustR{0.15} \def\ExhaustH{1.5} \draw[fill=ExhaustGray, draw=black] (\ExhaustX, \ExhaustY, \ExhaustZ) -- ++(0,0,\ExhaustH) arc (90:-90:{\ExhaustR} and 0.05) -- ++(0,0,-\ExhaustH) arc (90:270:{\ExhaustR} and 0.05); \fill[ExhaustGray!70!black] (\ExhaustX, \ExhaustY, \ExhaustZ+\ExhaustH) ellipse ({\ExhaustR} and 0.05); % Smoke puffs \node[circle, fill=SmokeGray, opacity=0.5, minimum size=10pt] at (\ExhaustX, \ExhaustY, \ExhaustZ+\ExhaustH+0.5) {}; \node[circle, fill=SmokeGray, opacity=0.4, minimum size=15pt] at (\ExhaustX+0.2, \ExhaustY, \ExhaustZ+\ExhaustH+0.8) {}; \node[circle, fill=SmokeGray, opacity=0.3, minimum size=20pt] at (\ExhaustX+0.5, \ExhaustY, \ExhaustZ+\ExhaustH+1.1) {}; % --- Headlights --- \fill[yellow!80!white, draw=black] (2.5, -\BodyW/2-0.01, \BodyZ+\BodyH-0.3) circle (0.2); \fill[yellow!80!white, draw=black] (2.5, \BodyW/2+0.01, \BodyZ+\BodyH-0.3) circle (0.2); \end{scope} \end{tikzpicture} \end{document}How the Code Works
-
Setup:
\documentclass[tikz, border=5mm]{standalone}: Creates a tight-fitting document around the drawing.\usepackage{tikz-3dplot}: Loads the necessary package for 3D perspective.\tdplotsetmaincoords{70}{110}: This is the key command for the 3D effect. It sets the viewing angle. You can change these numbers to rotate the tractor.\colorlet{...}: Defines custom colors, making it easy to change the tractor's color scheme in one place.
-
Drawing Order:
- In 3D-style drawing, the order is crucial. Objects are drawn from furthest to nearest to ensure they overlap correctly.
- The code starts with the ground shadow, then the far back wheel, the main body, the front wheels, the cabin, and finally the near back wheel which is closest to the viewer.
-
Components:
- Wheels: These are drawn as filled circles. The
\foreachloop adds simple black lines to represent tire treads, giving them more texture. - Body and Cabin: These are constructed as cuboids by drawing and filling polygons for each visible face. The coordinates for the vertices are calculated using
\defvariables, which makes the model parametric. - Windows: Drawn as light blue, semi-transparent (
opacity=0.6) polygons. They are drawn before the cabin frame so the red frame appears on top. - Exhaust Pipe: This is drawn as a simple cylinder with a few semi-transparent circles above it to simulate smoke.
- Details: Small touches like the steering wheel (visible through the window), headlights, and wheel rims add a lot of character and realism.
- Wheels: These are drawn as filled circles. The
How to Customize
- Change the Color: Simply modify the
TractorReddefinition. For example,\colorlet{TractorRed}{blue!70!black}for a blue tractor. - Change the View: Alter the values in
\tdplotsetmaincoords{70}{110}. The first number is rotation around the vertical axis, the second is the angle of elevation. - Change Proportions: All major dimensions (wheel radius, body length, etc.) are defined with
\def. You can easily change\Rback,\BodyL, etc., at the top of the code to alter the tractor's shape.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
qwen-max-2025-01-25Compare side by side →
claude-sonnet-4-20250514Compare side by side →
claude-3-7-sonnet-20250219-thinking-32kCompare side by side →
qwen3-235b-a22bCompare side by side →
gemini-2.5-pro-preview-05-06Compare side by side →
claude-3-7-sonnet-20250219-thinking-32kCompare side by side →
claude-sonnet-4-20250514Compare side by side →
mistral-medium-2505Compare side by side →
command-a-03-2025Compare side by side →
qwen-max-2025-01-25Compare side by side →
claude-sonnet-4-20250514Compare side by side →