Graphics, Figures & TablestikZ | Coordinate Parameters

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Coordinate Parameters

Post by psionman »

I am using Pgf Tikz to produce a diagram

It shows a mass at rest on a ramp. For most points I have been able to parameterise the coordinates (meaning that, for example, I can change the angle of the ramp or the mass size by changing a single parameter. The code follows:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary {shapes}

%Mass on ramp

\newcommand{\base}{14}
\newcommand{\massXposition}{6}
\newcommand{\massSide}{2}
\newcommand{\massHalf}{1}
\newcommand{\incline}{20}

\newcommand{\massVertex}{(intersection of \massXposition,0--\massXposition,1 and 0,0--\incline:1)}
\newcommand{\massCentre}{[rotate around={\incline:\massVertex}] \massVertex +(\massHalf,\massHalf)}

\begin{document}
\begin{tikzpicture}[scale=.5]

%Ramp
\draw  (0,0) -- (\incline:\base) -- (\incline:\base |- 0,0) -- cycle; 

%Mass
\draw [rotate around={\incline:\massVertex}] \massVertex rectangle +(\massSide,\massSide);
\fill \massCentre circle (2pt);
\draw [->] \massCentre --  +(-1,1);
\draw [->] \massCentre --  +(1,3);
\draw [->] \massCentre -- (5.85,6 |- 0,0);
%\draw [->] \massCentre -- (\massCentre |- 0,0);
\end{tikzpicture}
\end{document}
I now want to add an arrow vertically downwards from the centre of the mass. The line

Code: Select all

\draw [->] \massCentre -- (5.85,6 |- 0,0);
gives me this, but I have had to 'hard-code' the x-coordinate of the mass Centre. If I use

Code: Select all

\draw [->] \massCentre -- (\massCentre |- 0,0);
I get an error
Package tikz Error: Cannot parse this coordinate.
Also can someone explain how the relative coordinates in

Code: Select all

\draw [->] \massCentre --  +(-1,1);
work? I would have expected

Code: Select all

\draw [->] \massCentre --  +(-2,2);

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10344
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Coordinate Parameters

Post by Stefan Kottwitz »

Hi,

welcome to the board!

Have a look at Free body diagrams in TikZ, there's also a mass on a ramp, and arrows on a mass object.

Stefan
LaTeX.org admin
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

Re: tikZ | Coordinate Parameters

Post by psionman »

Thanks Stefan

I'll study with interest
Post Reply