LaTeX forum ⇒ Graphics, Figures & TablestikZ | Coordinate Parameters

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

tikZ | Coordinate Parameters

Postby psionman » Wed Dec 28, 2011 7:00 pm

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:

  1. \documentclass[a4paper,12pt]{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary {shapes}
  4.  
  5. %Mass on ramp
  6.  
  7. \newcommand{\base}{14}
  8. \newcommand{\massXposition}{6}
  9. \newcommand{\massSide}{2}
  10. \newcommand{\massHalf}{1}
  11. \newcommand{\incline}{20}
  12.  
  13. \newcommand{\massVertex}{(intersection of \massXposition,0--\massXposition,1 and 0,0--\incline:1)}
  14. \newcommand{\massCentre}{[rotate around={\incline:\massVertex}] \massVertex +(\massHalf,\massHalf)}
  15.  
  16. \begin{document}
  17. \begin{tikzpicture}[scale=.5]
  18.  
  19. %Ramp
  20. \draw (0,0) -- (\incline:\base) -- (\incline:\base |- 0,0) -- cycle;
  21.  
  22. %Mass
  23. \draw [rotate around={\incline:\massVertex}] \massVertex rectangle +(\massSide,\massSide);
  24. \fill \massCentre circle (2pt);
  25. \draw [->] \massCentre -- +(-1,1);
  26. \draw [->] \massCentre -- +(1,3);
  27. \draw [->] \massCentre -- (5.85,6 |- 0,0);
  28. %\draw [->] \massCentre -- (\massCentre |- 0,0);
  29. \end{tikzpicture}
  30. \end{document}


I now want to add an arrow vertically downwards from the centre of the mass. The line
  1. \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
  1. \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
  1. \draw [->] \massCentre -- +(-1,1);


work? I would have expected

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 9604
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Dec 28, 2011 9:47 pm

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

Postby psionman » Wed Dec 28, 2011 10:02 pm

Thanks Stefan

I'll study with interest


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests