Graphics, Figures & TablesHow to calculate half distance between the x coordinates?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

How to calculate half distance between the x coordinates?

Post by usr345 »

I am trying to create a new node like this:
tikZ-calculation.png
tikZ-calculation.png (998 Bytes) Viewed 1689 times
but don't understand, how to calculate x3 = (x2 - x1) /2

Here I tried to do it, but in vain.

Code: Select all

\pgfdeclareshape{variant}{ \inheritsavedanchors[from=rectangle]
  % this is nearly a rectangle
  \inheritanchorborder[from=rectangle] \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north} \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{west} \inheritanchor[from=rectangle]{east}

  \backgroundpath{
    %{{{ store lower left in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
%}}}

    % compute x3 --- here is the problem!
    \pgf@yc = \pgf@xb - \pgf@xa
    \pgf@yc = 0.5\pgf@yc
    \pgf@xc = \pgf@xa
    \advance \pgf@xc by \pgf@yc

%end of the problem

    \pgf@yc = \pgf@ya
    \advance\pgf@yc by - 10pt % this should be a parameter

    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    %{{{ construct 2 bottom lines
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
%}}}

    % Rectangle box
    \pgfpathrectanglecorners{\southwest}{\northeast}

  }
}
Last edited by usr345 on Wed Jun 08, 2011 5:35 pm, edited 1 time in total.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

How to calculate half distance between the x coordinates?

Post by usr345 »

I solved it by using the command:

Code: Select all

\pgf@xc = .5\wd\pgfnodeparttextbox
that gives me 1/2 of the box width
Post Reply