Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have created the following figure:

\documentclass[border=18pt]{standalone}
\usepackage{tikz}


\begin{document}

\begin{tikzpicture}

\begin{scope}[>=latex]
\draw [->] (-3,0) -- (3,0);
\draw [->] (0,-1.5) -- (0,6.5);
\end{scope}

\filldraw [black] (0,0) circle (2pt);

\def\centerx{0}
\def\centery{4}

\def\side{3}
\def\rot{40}
\def\sidePerc{0.25}
\pgfmathparse{\side * sqrt(2)/2 }\let\veclen\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\llx\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\lly\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\lrx\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\lry\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\urx\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\ury\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\ulx\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\uly\pgfmathresult


\pgfmathparse{\llx*cos(\rot) - \lly*sin(\rot)}\let\llxr\pgfmathresult
\pgfmathparse{\llx*sin(\rot) + \lly*cos(\rot)}\let\llyr\pgfmathresult
\pgfmathparse{\lrx*cos(\rot) - \lry*sin(\rot)}\let\lrxr\pgfmathresult
\pgfmathparse{\lrx*sin(\rot) + \lry*cos(\rot)}\let\lryr\pgfmathresult
\pgfmathparse{\urx*cos(\rot) - \ury*sin(\rot)}\let\urxr\pgfmathresult
\pgfmathparse{\urx*sin(\rot) + \ury*cos(\rot)}\let\uryr\pgfmathresult
\pgfmathparse{\ulx*cos(\rot) - \uly*sin(\rot)}\let\ulxr\pgfmathresult
\pgfmathparse{\ulx*sin(\rot) + \uly*cos(\rot)}\let\ulyr\pgfmathresult



\coordinate (A') at ({\llxr+\centerx},{\llyr+\centery});
\coordinate (B') at ({\lrxr+\centerx},{\lryr+\centery});
\coordinate (C') at ({\urxr+\centerx},{\uryr+\centery});
\coordinate (D') at ({\ulxr+\centerx},{\ulyr+\centery});


\filldraw [black] (A') circle (2pt)
            (B') circle (2pt)
            (C') circle (2pt)
            (D') circle (2pt);

\draw (A')--(B')--(C')--(D')--(A');

\pgfmathparse{sqrt( (\sidePerc*\sidePerc+0.25)*\side*\side )}\let\pveclen\pgfmathresult
\pgfmathparse{asin(\sidePerc*\side/\pveclen)}\let\angle\pgfmathresult
\pgfmathparse{neg(\pveclen*sin(\angle))}\let\cblx\pgfmathresult
\pgfmathparse{neg(\pveclen*cos(\angle))}\let\cbly\pgfmathresult
\pgfmathparse{neg(\cblx)}\let\cbrx\pgfmathresult
\pgfmathparse{\cbly}\let\cbry\pgfmathresult
\pgfmathparse{neg(\cbry)}\let\crbx\pgfmathresult
\pgfmathparse{neg(\cbrx)}\let\crby\pgfmathresult
\pgfmathparse{\crbx}\let\crtx\pgfmathresult
\pgfmathparse{neg(\crby)}\let\crty\pgfmathresult
\pgfmathparse{\crty}\let\ctrx\pgfmathresult
\pgfmathparse{\crtx}\let\ctry\pgfmathresult
\pgfmathparse{neg(\ctrx)}\let\ctlx\pgfmathresult
\pgfmathparse{\ctry}\let\ctly\pgfmathresult
\pgfmathparse{neg(\crtx)}\let\cltx\pgfmathresult
\pgfmathparse{\crty}\let\clty\pgfmathresult
\pgfmathparse{neg(\crbx)}\let\clbx\pgfmathresult
\pgfmathparse{\crby)}\let\clby\pgfmathresult



\pgfmathparse{\cblx*cos(\rot) - \cbly*sin(\rot)}\let\cblxr\pgfmathresult
\pgfmathparse{\cblx*sin(\rot) + \cbly*cos(\rot)}\let\cblyr\pgfmathresult
\pgfmathparse{\cbrx*cos(\rot) - \cbry*sin(\rot)}\let\cbrxr\pgfmathresult
\pgfmathparse{\cbrx*sin(\rot) + \cbry*cos(\rot)}\let\cbryr\pgfmathresult
\pgfmathparse{\clbx*cos(\rot) - \clby*sin(\rot)}\let\clbxr\pgfmathresult
\pgfmathparse{\clbx*sin(\rot) + \clby*cos(\rot)}\let\clbyr\pgfmathresult
\pgfmathparse{\cltx*cos(\rot) - \clty*sin(\rot)}\let\cltxr\pgfmathresult
\pgfmathparse{\cltx*sin(\rot) + \clty*cos(\rot)}\let\cltyr\pgfmathresult
\pgfmathparse{\ctrx*cos(\rot) - \ctry*sin(\rot)}\let\ctrxr\pgfmathresult
\pgfmathparse{\ctrx*sin(\rot) + \ctry*cos(\rot)}\let\ctryr\pgfmathresult
\pgfmathparse{\ctlx*cos(\rot) - \ctly*sin(\rot)}\let\ctlxr\pgfmathresult
\pgfmathparse{\ctlx*sin(\rot) + \ctly*cos(\rot)}\let\ctlyr\pgfmathresult
\pgfmathparse{\crtx*cos(\rot) - \crty*sin(\rot)}\let\crtxr\pgfmathresult
\pgfmathparse{\crtx*sin(\rot) + \crty*cos(\rot)}\let\crtyr\pgfmathresult
\pgfmathparse{\crbx*cos(\rot) - \crby*sin(\rot)}\let\crbxr\pgfmathresult
\pgfmathparse{\crbx*sin(\rot) + \crby*cos(\rot)}\let\crbyr\pgfmathresult


\coordinate (AC') at ({\cblxr+\centerx},{\cblyr+\centery});
\coordinate (BC') at ({\cbrxr+\centerx},{\cbryr+\centery});
\coordinate (CC') at ({\crbxr+\centerx},{\crbyr+\centery});
\coordinate (DC') at ({\crtxr+\centerx},{\crtyr+\centery});
\coordinate (EC') at ({\ctrxr+\centerx},{\ctryr+\centery});
\coordinate (FC') at ({\ctlxr+\centerx},{\ctlyr+\centery});
\coordinate (GC') at ({\cltxr+\centerx},{\cltyr+\centery});
\coordinate (HC') at ({\clbxr+\centerx},{\clbyr+\centery});

\filldraw [black] (AC') circle (2pt)
            (BC') circle (2pt)
            (CC') circle (2pt)
            (DC') circle (2pt)
            (EC') circle (2pt)
            (FC') circle (2pt)
            (GC') circle (2pt)
            (HC') circle (2pt);

\draw [shorten >=-2cm, >=stealth](AC')--(0,0);
\draw [shorten >=-2cm](BC')--(0,0);
\draw [shorten >=-2cm](GC')--(0,0);
\draw [shorten >=-2cm](HC')--(0,0);

\draw [-] (-3,-1) -- (3,-1);

\node[draw] at (2,-1.2) {Focal Plane};

\coordinate (P1) at (-3,-1);
\coordinate (P2) at (3,-1);
\clip (P1) -- (P2);

\end{tikzpicture}
\end{document}

enter image description here

now i want to find the intersection of rays from the points "inside" the circumference of the rectangle and that go through the origin, with the focal plane. What i have done is to create lines from the points to the orign and then shortened them so that they intersect the focal plane. How do i chop the shortened lines after the intersection? Also it's my first tikz figure so please keep the guns down :P

share|improve this question
4  
Instead of posting a code fragment (especially such a large one) you should post a complete compilable document that people can play with. Such a document will also show which tikz libraries are needed to compile the code. But given the size of your example, surely a better strategy is to create a small example that shows just the problem you're having. You don't need all of this code to make the problem understandable. –  Alan Munn Jul 9 '12 at 17:31
    
possible duplicate of Intersection with rays in TikZ –  Jake Jul 9 '12 at 17:48
    
@AlanMunn it's not a fragment. It's the whole figure. The rest of the document is irrelevant. –  msmechanized Jul 9 '12 at 22:45
    
It is a fragment. I can't copy it into my editor, save it and compile it without doing extra work (and possibly guessing which TikZ libraries to load). So the "rest of the document" is relevant. Plus, it's far bigger than you need to actually demonstrate the problem. See I've just been told I have to write a minimal example, what is that?. –  Alan Munn Jul 9 '12 at 22:53
    
@AlanMunn hmm, indeed you are right. I'm sorry. Next time ill put a minimal working example. –  msmechanized Jul 9 '12 at 23:00
add comment

1 Answer

up vote 2 down vote accepted

Add coordinate[pos=2](b); to get a line enough long and to get an intersection. You need to use intersections library.

Some examples

In the first case the two lines have no intersection. In the second case with the use of shorten you can see an intersection but paths are only defined between the points given like in the first case. In the third case you can get an intersection.

enter image description here

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}
\draw[name path=d1] (0,0) -- (2,0);
\draw[name path=d2] (0,-2) -- (2,-0.5); 
%\fill [red, name intersections={of=d1 and d2, by=x}]
%       (x) circle (2pt); 
\end{tikzpicture}

\vspace{1cm}
\begin{tikzpicture}
\draw[name path=d1,shorten >=-2cm] (0,0) -- (2,0) ;
\draw[name path=d2,shorten >=-2cm] (0,-2) -- (2,-0.5); 
% \fill [red, name intersections={of=d1 and d2, by=x}]
%        (x) circle (2pt);  
\end{tikzpicture}

\vspace{1cm}  
\begin{tikzpicture}
\draw[shorten >=-2cm] (0,0) -- (2,0)  coordinate[pos=2](b); 
 \path[name path=d1] (0,0)--(b);         
\draw[shorten >=-2cm] (0,-2) -- (2,-0.5)  coordinate[pos=2](c);
 \path[name path=d2] (0,-2)--(c);   
 \fill [red, name intersections={of=d1 and d2, by=x}]
        (x) circle (2pt);  
\end{tikzpicture}  
\end{document}  

Main code

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{%
  arrows,
  calc ,intersections
}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1]


%Draw axis
\begin{scope}[>=latex]
\draw [->] (-3,0) -- (3,0);
\draw [->] (0,-1.5) -- (0,6.5);
\end{scope}
%\draw[step=.5,gray,very thin] (-2.9,-0.9) grid (2.9,6.4);

\filldraw [black] (0,0) circle (2pt);


\def\centerx{0}
\def\centery{4}

\def\side{3}
\def\rot{40}
\def\sidePerc{0.25}
\pgfmathparse{\side * sqrt(2)/2 }\let\veclen\pgfmathresult

%llx : Lower left x
%lly : Lower left y
%lrx : Lower right x
%urx : Upper right x


%Vector of lower left point (Lower Left x and y)
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\llx\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\lly\pgfmathresult

%Vector of lower right point (Lower Left x and y)
\pgfmathparse{\veclen*sqrt(2)/2}\let\lrx\pgfmathresult
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\lry\pgfmathresult

%Vector of upper right point (Lower Left x and y)
\pgfmathparse{\veclen*sqrt(2)/2}\let\urx\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\ury\pgfmathresult

%Vector of upper left left point (Lower Left x and y)
\pgfmathparse{neg(\veclen)*sqrt(2)/2}\let\ulx\pgfmathresult
\pgfmathparse{\veclen*sqrt(2)/2}\let\uly\pgfmathresult

%Rotation of the above vectors
\pgfmathparse{\llx*cos(\rot) - \lly*sin(\rot)}\let\llxr\pgfmathresult
\pgfmathparse{\llx*sin(\rot) + \lly*cos(\rot)}\let\llyr\pgfmathresult

\pgfmathparse{\lrx*cos(\rot) - \lry*sin(\rot)}\let\lrxr\pgfmathresult
\pgfmathparse{\lrx*sin(\rot) + \lry*cos(\rot)}\let\lryr\pgfmathresult

\pgfmathparse{\urx*cos(\rot) - \ury*sin(\rot)}\let\urxr\pgfmathresult
\pgfmathparse{\urx*sin(\rot) + \ury*cos(\rot)}\let\uryr\pgfmathresult

\pgfmathparse{\ulx*cos(\rot) - \uly*sin(\rot)}\let\ulxr\pgfmathresult
\pgfmathparse{\ulx*sin(\rot) + \uly*cos(\rot)}\let\ulyr\pgfmathresult


%\coordinate (A) at ({\llx+\centerx},{\lly+\centery});
%\coordinate (B) at ({\lrx+\centerx},{\lry+\centery});
%\coordinate (C) at ({\urx+\centerx},{\ury+\centery});
%\coordinate (D) at ({\ulx+\centerx},{\uly+\centery});
%
%%Draw the points
%\filldraw [black] (A) circle (2pt)
%           (B) circle (2pt)
%           (C) circle (2pt)
%           (D) circle (2pt);
%
%%draw the square
%\draw (A)--(B)--(C)--(D)--(A);


\coordinate (A') at ({\llxr+\centerx},{\llyr+\centery});
\coordinate (B') at ({\lrxr+\centerx},{\lryr+\centery});
\coordinate (C') at ({\urxr+\centerx},{\uryr+\centery});
\coordinate (D') at ({\ulxr+\centerx},{\ulyr+\centery});

%Draw the points
\filldraw [black] (A') circle (2pt)
            (B') circle (2pt)
            (C') circle (2pt)
            (D') circle (2pt);

%draw the square
\draw (A')--(B')--(C')--(D')--(A');



%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               Circle Points Section
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%distance in side percentade from y axis or the lower left "circles" points
\pgfmathparse{sqrt( (\sidePerc*\sidePerc+0.25)*\side*\side )}\let\pveclen\pgfmathresult
\pgfmathparse{asin(\sidePerc*\side/\pveclen)}\let\angle\pgfmathresult

%cblx : Circle bottom left x
%clbx : Left bottom y


%Vector of lower left point (Lower Left x and y)
\pgfmathparse{neg(\pveclen*sin(\angle))}\let\cblx\pgfmathresult
\pgfmathparse{neg(\pveclen*cos(\angle))}\let\cbly\pgfmathresult

\pgfmathparse{neg(\cblx)}\let\cbrx\pgfmathresult
\pgfmathparse{\cbly}\let\cbry\pgfmathresult

\pgfmathparse{neg(\cbry)}\let\crbx\pgfmathresult
\pgfmathparse{neg(\cbrx)}\let\crby\pgfmathresult

\pgfmathparse{\crbx}\let\crtx\pgfmathresult
\pgfmathparse{neg(\crby)}\let\crty\pgfmathresult

\pgfmathparse{\crty}\let\ctrx\pgfmathresult
\pgfmathparse{\crtx}\let\ctry\pgfmathresult

\pgfmathparse{neg(\ctrx)}\let\ctlx\pgfmathresult
\pgfmathparse{\ctry}\let\ctly\pgfmathresult

\pgfmathparse{neg(\crtx)}\let\cltx\pgfmathresult
\pgfmathparse{\crty}\let\clty\pgfmathresult

\pgfmathparse{neg(\crbx)}\let\clbx\pgfmathresult
\pgfmathparse{\crby)}\let\clby\pgfmathresult


%\coordinate (AC) at ({\cblx+\centerx},{\cbly+\centery});
%\coordinate (BC) at ({\cbrx+\centerx},{\cbry+\centery});
%\coordinate (CC) at ({\crbx+\centerx},{\crby+\centery});
%\coordinate (DC) at ({\crtx+\centerx},{\crty+\centery});
%\coordinate (EC) at ({\ctrx+\centerx},{\ctry+\centery});
%\coordinate (FC) at ({\ctlx+\centerx},{\ctly+\centery});
%\coordinate (GC) at ({\cltx+\centerx},{\clty+\centery});
%\coordinate (HC) at ({\clbx+\centerx},{\clby+\centery});
%
%\filldraw [black] (AC) circle (2pt)
%           (BC) circle (2pt)
%           (CC) circle (2pt)
%           (DC) circle (2pt)
%           (EC) circle (2pt)
%           (FC) circle (2pt)
%           (GC) circle (2pt)
%           (HC) circle (2pt);

%%%%%%%%%%%%%% Rotations %%%%%%%%%%%%%

\pgfmathparse{\cblx*cos(\rot) - \cbly*sin(\rot)}\let\cblxr\pgfmathresult
\pgfmathparse{\cblx*sin(\rot) + \cbly*cos(\rot)}\let\cblyr\pgfmathresult

\pgfmathparse{\cbrx*cos(\rot) - \cbry*sin(\rot)}\let\cbrxr\pgfmathresult
\pgfmathparse{\cbrx*sin(\rot) + \cbry*cos(\rot)}\let\cbryr\pgfmathresult

\pgfmathparse{\clbx*cos(\rot) - \clby*sin(\rot)}\let\clbxr\pgfmathresult
\pgfmathparse{\clbx*sin(\rot) + \clby*cos(\rot)}\let\clbyr\pgfmathresult

\pgfmathparse{\cltx*cos(\rot) - \clty*sin(\rot)}\let\cltxr\pgfmathresult
\pgfmathparse{\cltx*sin(\rot) + \clty*cos(\rot)}\let\cltyr\pgfmathresult

\pgfmathparse{\ctrx*cos(\rot) - \ctry*sin(\rot)}\let\ctrxr\pgfmathresult
\pgfmathparse{\ctrx*sin(\rot) + \ctry*cos(\rot)}\let\ctryr\pgfmathresult

\pgfmathparse{\ctlx*cos(\rot) - \ctly*sin(\rot)}\let\ctlxr\pgfmathresult
\pgfmathparse{\ctlx*sin(\rot) + \ctly*cos(\rot)}\let\ctlyr\pgfmathresult

\pgfmathparse{\crtx*cos(\rot) - \crty*sin(\rot)}\let\crtxr\pgfmathresult
\pgfmathparse{\crtx*sin(\rot) + \crty*cos(\rot)}\let\crtyr\pgfmathresult

\pgfmathparse{\crbx*cos(\rot) - \crby*sin(\rot)}\let\crbxr\pgfmathresult
\pgfmathparse{\crbx*sin(\rot) + \crby*cos(\rot)}\let\crbyr\pgfmathresult


\coordinate (AC') at ({\cblxr+\centerx},{\cblyr+\centery});
\coordinate (BC') at ({\cbrxr+\centerx},{\cbryr+\centery});
\coordinate (CC') at ({\crbxr+\centerx},{\crbyr+\centery});
\coordinate (DC') at ({\crtxr+\centerx},{\crtyr+\centery});
\coordinate (EC') at ({\ctrxr+\centerx},{\ctryr+\centery});
\coordinate (FC') at ({\ctlxr+\centerx},{\ctlyr+\centery});
\coordinate (GC') at ({\cltxr+\centerx},{\cltyr+\centery});
\coordinate (HC') at ({\clbxr+\centerx},{\clbyr+\centery});

\filldraw [black] (AC') circle (2pt)
                  (BC') circle (2pt)
                  (CC') circle (2pt)
                  (DC') circle (2pt)
                  (EC') circle (2pt)
                  (FC') circle (2pt)
                  (GC') circle (2pt)
                  (HC') circle (2pt);
%[shorten >=-2cm]
\draw [ >=stealth](AC')--(0,0);
\draw (BC')--(0,0) coordinate[pos=2](b);
\draw (GC')--(0,0) coordinate[pos=2](g); 
\draw (HC')--(0,0) coordinate[pos=2](h); 

\path[name path=bc] (BC')--(b);
\path[name path=gc] (GC')--(g);
\path[name path=hc] (HC')--(h);
\draw [-,name path=FP] (-3,-1) -- (3,-1);

\node[draw] at (2,-1.2) {Focal Plane};
\fill [red, name intersections={of=FP and bc, by=xb}]
       (xb) circle (2pt);
\fill [red, name intersections={of=FP and gc, by=xg}]
       (xg) circle (2pt);  
\fill [red, name intersections={of=FP and hc, by=xh}]
       (xh) circle (2pt); 
\draw  (0,0) -- (xb); \draw  (0,0) --(xg); \draw  (0,0) --(xh) ;
\coordinate (P1) at (-3,-1);
\coordinate (P2) at (3,-1);
\clip (P1) -- (P2);


\end{tikzpicture}

\end{figure}
\end{document}   

enter image description here

share|improve this answer
    
I thought the line was already long enough to get an intersection by just using the shorten directive. You did not do what i wanted but your code helped me solve the problem. So thanks. –  msmechanized Jul 9 '12 at 23:01
    
@msmechanized No sorry but I think you are wrong. I updated my answer with some examples. shorten don't change anything, the path is defined without adding '2cm' in your case. –  Alain Matthes Jul 10 '12 at 6:56
    
your example is explained better now. But i wanted to stop the line after the intersection. So i removed the shorten directive and added a '\path' with the points involved so that i could compute the intersection with "invisible" lines, and then draw the actual line i wanted. Still thank you man. –  msmechanized Jul 10 '12 at 8:52
    
@msmechanized ok you take the good way. –  Alain Matthes Jul 10 '12 at 9:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.