Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The time index of intersection point of line and line. #732

Open
QJLc opened this issue Aug 24, 2019 · 3 comments
Open

The time index of intersection point of line and line. #732

QJLc opened this issue Aug 24, 2019 · 3 comments

Comments

@QJLc
Copy link

QJLc commented Aug 24, 2019

The lines

\pgf@ifsolution@duplicate{\pgf@intersect@solution@candidate}{%
% ah - we a duplicate. Apparently, we have a hit on an
% endpoint.
}{%
\global\advance\pgf@intersect@solutions by1\relax%
\expandafter\global\expandafter\let\csname pgfpoint@g@intersect@solution@\the\pgf@intersect@solutions\endcsname=\pgf@intersect@solution@candidate
\ifpgf@intersect@sort%
\pgf@xc=\pgf@x%
\pgf@yc=\pgf@y%
\pgf@process{\pgfpointdiff{\pgfpoint@intersect@start@a}{\pgfpoint@intersect@end@a}}%
\edef\pgf@marshal{%
\noexpand\pgfmathveclen@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgf@ya}}%
}%
\pgf@marshal%

are used to define \pgf@intersect@time@a. I think that, the \pgf@x and \pgf@y in lines 364 and 365, could be coordinates of current intersection point, but their value may be modified by \pgf@ifsolution@duplicate in line 357.

The line 366 gets the vector "start--end", stored in \pgf@x and \pgf@y, the line 368 gets the length of "start--end", so, the line 368 could be modified.

A possible modification starting from line 363 would be:

            \ifpgf@intersect@sort%
                \pgf@intersect@solution@candidate%   <-- add this line
                \pgf@xc=\pgf@x%
                \pgf@yc=\pgf@y%
                \pgf@process{\pgfpointdiff{\pgfpoint@intersect@start@a}{\pgfpoint@intersect@end@a}}%
                \edef\pgf@marshal{%
                    \noexpand\pgfmathveclen@{\pgfmath@tonumber{\pgf@x}}{\pgfmath@tonumber{\pgf@y}}%  <-- this line is modified
                }%
               \pgf@marshal%

I tried this:

\begin{pgfpicture}
  \pgfintersectionsortbyfirstpath
  \pgfintersectionofpaths
  {
    \pgfpathmoveto{\pgfpoint{1cm}{0cm}}
    \pgfpathlineto{\pgfpoint{1cm}{3cm}}
    \pgfpathlineto{\pgfpoint{2cm}{3cm}}
    \pgfpathlineto{\pgfpoint{2cm}{0cm}}
    \pgfgetpath\temppath
    \pgfusepath{stroke}
    \pgfsetpath\temppath
  }{
    \pgfpathmoveto{\pgfpoint{0cm}{2cm}}
    \pgfpathlineto{\pgfpoint{3cm}{2cm}}
    \pgfpathlineto{\pgfpoint{3cm}{1cm}}
    \pgfpathlineto{\pgfpoint{0cm}{1cm}}
    \pgfgetpath\temppath
    \pgfusepath{stroke}
    \pgfsetpath\temppath
  }
  \foreach \s in {1,...,\pgfintersectionsolutions}
  {\pgfpathcircle{\pgfpointintersectionsolution{\s}}{2pt}}
  \pgfusepath{stroke}
\end{pgfpicture}

\def\showrecord#1#2#3#4{%
#1;#2;#3;#4;%
}
\makeatletter
\edef\pointA{\csname pgfpoint@g@intersect@solution@1@props\endcsname}
\edef\pointB{\csname pgfpoint@g@intersect@solution@2@props\endcsname}
\edef\pointC{\csname pgfpoint@g@intersect@solution@3@props\endcsname}
\edef\pointD{\csname pgfpoint@g@intersect@solution@4@props\endcsname}
\expandafter\showrecord\pointA\relax%
\expandafter\showrecord\pointB\relax%
\expandafter\showrecord\pointC\relax%
\expandafter\showrecord\pointD\relax%
\makeatother

And output numbers are:

0;0;0.6667;;
0;2;0.33336;;
2;0;2.33336;;
2;2;2.6667;;

These may be expected.

@hmenke

This comment has been minimized.

@QJLc

This comment has been minimized.

@QJLc QJLc changed the title pgflibraryintersections.code.tex The time index of intersection point of line and line. Aug 24, 2019
@ghost
Copy link

ghost commented Sep 16, 2019

The pgfplots library has such a functionality in the sense that it allows one to decompose the path into intersection segments. There is also \pgfintersectiongetsolutiontime, but it does not give the time in the sense of a percentage at which the intersection is located. See also https://tex.stackexchange.com/q/432532.

@hmenke hmenke added this to the 3.1.6 milestone Dec 17, 2019
@hmenke hmenke modified the milestones: 3.1.6, 3.1.7 Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants