Graphics, Figures & TablesTikZ- extracting coordinate components

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fenn
Posts: 5
Joined: Sun Jul 05, 2009 9:21 pm

TikZ- extracting coordinate components

Post by fenn »

This is a question regarding TikZ and PGF. I'm trying to extract the x-, y-, and z-components of a coordinate into a macro so that the values can be manipulated using \pgfmathparse commands. As an example:

Code: Select all

\begin{tikzpicture}
 \coordinate (A) at (2.34, 3.21);
 \pgfmathsetmacro{\Ax}{ "x-component of coordinate (A)" } 
 \Ax
\end{tikzpicture}
I would like this example to output the value 2.34, the (unitless) x-component of coordinate (A). From what I can tell, there is no way to simply define "x-component of coordinate (A)".

I would like to get this information since I am developing a LaTeX tool to perform vector math, and thought it would be convenient to specify vectors using the TikZ coordinate system. I essentially need to find a way to bridge the gap between specifying coordinates and defining macros that work within \pgfmathparse commands.

I have looked into the "let" operation that will pick out the x- and y-component of a coordinate as \x# and \y# macros, but there are several problems with this. First, it contains the "pt" unit, and this value will only exist within a \path or \draw operation. I can use this value to define another coordinate, but then I'm back where I started. Finally, there is no macro for the z-component.

Any suggestions or ideas are welcome!

Jeff

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

chandra
Posts: 3
Joined: Sun Mar 27, 2011 4:06 pm

TikZ- extracting coordinate components

Post by chandra »

Perhaps the solution at {TeX} SE might give you the solution you seek.

Also, section "78.6 Extracting Coordinates" p 724 of the latest PGF manual.

I was after the same thing and came across your post.

Sorry this answer is more than a year late!
Post Reply