1

Is it possible to write a Latex macro based on \includegraphics so that given two points A and B this will become the lower side of the image (i.e., the image will be translated, scaled, and rotated accordingly)? This would give a functionality equivalent to that provided by Geogebra. It should have 3 arguments - the two pints and the image file name.

bandi
  • 171

1 Answers1

1

With sloped TikZ option you can already go a long way: (read the notes in the code to understand what it does)

%! TEX program = pdflatex
\documentclass{article}
\usepackage{tikz,fp}
\usetikzlibrary{calc}

\makeatletter ... (copy code from https://tex.stackexchange.com/a/38500/250119 and paste here) \makeatother

\usepackage{graphicx} \begin{document}

\begin{tikzpicture} \path % specify the corner points. (2, 3) coordinate (b) (4, 5) coordinate (a) ;

\calcLength(a,b){mylen}  % store the distance between 2 points into mylen.
% DO NOT include a space e.g. between a and b

\path
    (a) to node [midway, sloped, allow upside down, above, inner sep=0] {
        \includegraphics[width=\mylen pt]{a.png}
    } (b);

\end{tikzpicture}

\end{document}

the remaining part is to compute the distance between two nodes and pass it to the width of includegraphics.

It's the reader's exercise on how to wrap the functionality into a macro.


alternative question title (for searching): How can I include an image in TikZ with corners anchored at two points?

user202729
  • 7,143