{"id":320,"date":"2011-06-27T21:03:46","date_gmt":"2011-06-27T21:03:46","guid":{"rendered":"http:\/\/devnot.wordpress.com\/?p=320"},"modified":"2019-12-15T15:23:09","modified_gmt":"2019-12-15T14:23:09","slug":"find-out-where-a-vector-intersects-a-horizontal-or-vertical-line","status":"publish","type":"post","link":"https:\/\/thomas-jansen.eu\/?p=320","title":{"rendered":"Find out where a vector intersects a horizontal (or vertical) line"},"content":{"rendered":"\n\n\n<p>Of course the line intersection method can be used but in case of horizontal or vertical lines a quicker solution is available.<\/p>\n\n\n\n<p>Assume&nbsp; the vector V1 defined by points P1 and P2. and the horizontal line is&nbsp; through point P<\/p>\n\n\n\n<p>The offset of the intersection is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/thomas-jansen.eu\/wp-content\/ql-cache\/quicklatex.com-0d3e48625a614a2920d46d078d5afcb1_l3.svg\" class=\"ql-img-inline-formula \" alt=\"&#111;&#102;&#102;&#115;&#101;&#116;&#32;&#61;&#32;&#92;&#100;&#102;&#114;&#97;&#99;&#123;&#80;&#95;&#121;&#32;&#45;&#32;&#80;&#49;&#95;&#121;&#125;&#123;&#80;&#50;&#95;&#121;&#32;&#45;&#32;&#80;&#49;&#95;&#121;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"42\" width=\"162\" style=\"vertical-align: -18px;\"\/><\/pre>\n\n\n\n<p>Lets say P1 is 10,10 P2 20,20 and P.y 0,15<\/p>\n\n\n\n<p>In this case&nbsp; (15-10)\/(20-10)&nbsp; is 0.5<\/p>\n\n\n\n<p>If P1 and P2 is revered it will be (15-20)\/(10-20) = -5\/-10 = 0.5.<\/p>\n\n\n\n<p><strong>Note:<\/strong><br>There is a\u00a0 special case if the vector is parallel or on the horizontal line, in that case, there is no intersection. In that case, p2.y\u00a0&#8211; p1y is zero. This situation must be checked since it will also prevent a division by zero. You probably also want to limit very small values of this value since it may result in very large (positive or negatively) offset values.<\/p>\n\n\n\n<p><strong>Vertical lines:<\/strong><br>In case of a vertical line replace all .y above by x.<\/p>\n\n\n\n<p><strong>Calculating the intersection point:<\/strong><br>The offset when the vector is hit is always >= 0.0 and &lt;= 1.0,\u00a0 otherwise, it is on the extended vector.<\/p>\n\n\n\n<p>Calculating the intersection point on the(extended)&nbsp; vector is trivial<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/thomas-jansen.eu\/wp-content\/ql-cache\/quicklatex.com-ea9ab6e3b7f7ee743f8ced7b25c4ee0e_l3.svg\" class=\"ql-img-inline-formula \" alt=\"&#120;&#32;&#61;&#32;&#112;&#49;&#95;&#120;&#32;&#43;&#40;&#112;&#50;&#95;&#120;&#45;&#112;&#49;&#95;&#120;&#41;&#32;&#42;&#32;&#111;&#102;&#102;&#115;&#101;&#116;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"238\" style=\"vertical-align: -4px;\"\/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/thomas-jansen.eu\/wp-content\/ql-cache\/quicklatex.com-560f1556e04c96d5f18eebb793781922_l3.svg\" class=\"ql-img-inline-formula \" alt=\"&#121;&#32;&#61;&#32;&#112;&#49;&#95;&#121;&#32;&#43;&#40;&#112;&#50;&#95;&#121;&#45;&#112;&#49;&#95;&#121;&#41;&#32;&#42;&#32;&#111;&#102;&#102;&#115;&#101;&#116;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"236\" style=\"vertical-align: -6px;\"\/><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Of course the line intersection method can be used but in case of horizontal or vertical lines a quicker solution is available. Assume&nbsp; the vector V1 defined by points P1 and P2. and the horizontal line is&nbsp; through point P The offset of the intersection is: $offset = \\dfrac{P_y &#8211; P1_y}{P2_y &#8211; P1_y}$ Lets say [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-geometry"],"_links":{"self":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320"}],"version-history":[{"count":2,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":617,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions\/617"}],"wp:attachment":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}