{"id":174,"date":"2011-05-28T12:27:45","date_gmt":"2011-05-28T12:27:45","guid":{"rendered":"http:\/\/devnot.wordpress.com\/?p=174"},"modified":"2011-05-28T12:27:45","modified_gmt":"2011-05-28T12:27:45","slug":"the-dot-product","status":"publish","type":"post","link":"https:\/\/thomas-jansen.eu\/?p=174","title":{"rendered":"The dot product"},"content":{"rendered":"<p><a href=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-187\" title=\"dot0\" src=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot01.png\" alt=\"\" width=\"227\" height=\"153\" \/><\/a><\/p>\n<p>Formula:\u00a0 dx1 * dx2 + dy1 * dy2 + dz1 * dz1<br \/>\n<small><br \/>\ndx1 is the delta between the two x coordinates (last &#8211; first) of vector V1.<br \/>\ndx2 is the delta between the two x coordinates (last &#8211; first) of vector V2.<br \/>\ndy1 is the delta between the two y coordinates (last &#8211; first) of vector V1.<br \/>\ndy2 is the delta between the two y coordinates (last &#8211; first) of vector V2.<br \/>\ndz1 is the delta between the two z coordinates (last &#8211; first) of vector V1.<br \/>\ndz2 is the delta between the two z coordinates (last &#8211; first) of vector V2.<br \/>\n<\/small><\/p>\n<p><span style=\"text-decoration:underline;\">Check of 90 angles<\/span><\/p>\n<p>The dot product is actually a representation of the cosine. When the internal vector of two vectors angle is 90 degrees the dot product is always zero.<\/p>\n<p><span style=\"text-decoration:underline;\">Project point on vector<\/span><\/p>\n<p>Project P on vector V1<\/p>\n<p><a href=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot12.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-179\" title=\"dot1\" src=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot12.png\" alt=\"\" width=\"225\" height=\"150\" \/><\/a><\/p>\n<p>Projection can be done using the dot product.<\/p>\n<p>You can chose to normalize the vector, this is how I learned it.<\/p>\n<p>Normalizing a vector requires you to make its length 1 but keeping its direction.<\/p>\n<pre>length = sqrt(\u00a0 ((vx2 - vx1) * (vx2 - vx1)) + ((vy2 - vy1) * (vy2 - vy1))\u00a0 +( (vz2 - vz1) * (vz2 - vz1)) );\n\nvx2 = vx1 + (vx2 - vx1) \/ length;\n\nvy2 = vy1 + (vy2 - vy1) \/ length;\n\nvz2 = vz1 + (vz2 - vz1) \/ length;<\/pre>\n<p>Note: It is often more efficient to calculate the delta&#8217;s up front.<\/p>\n<p><a href=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot22.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-182\" title=\"dot2\" src=\"http:\/\/510245153.swh.strato-hosting.eu\/wp-content\/uploads\/2011\/05\/dot22.png\" alt=\"\" width=\"225\" height=\"150\" \/><\/a><\/p>\n<p>The dot vector can be used to project a point on a vector (line).<\/p>\n<p>The result will be 3 * 1 + 2 * 0\u00a0 + 0 * 0 = 3<\/p>\n<p>Now vector |V1| multiplied with 3 will point to the projection point.<\/p>\n<p><span style=\"text-decoration:underline;\">Alternative<\/span><\/p>\n<p>Alternatively do not normalize the vector. In that case the result will be 3 * 4 + 2 * 0\u00a0 + 0 * 0 = 12.<\/p>\n<p>When you look at the original formula you can divide it by the length of V1 (4) to get the offset relatively to the |V1| vector.<\/p>\n<p>To get the offset to the original vector divide by the length again. Which will give offset 1.0. Useful thing is you will save the square.<\/p>\n<p>For a 2d vector and a point the formula becomes:<\/p>\n<p>(vx2 &#8211; vx1) * (px -vx1) + (vy2 &#8211; vy1) * (py &#8211; vy1)<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>((vx2 &#8211; vx1) *\u00a0 (vx2 &#8211; vx1)) +\u00a0 ( (vy2 &#8211; vy1) * (vy2 &#8211; vy1))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Formula:\u00a0 dx1 * dx2 + dy1 * dy2 + dz1 * dz1 dx1 is the delta between the two x coordinates (last &#8211; first) of vector V1. dx2 is the delta between the two x coordinates (last &#8211; first) of vector V2. dy1 is the delta between the two y coordinates (last &#8211; first) of [&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":[24],"class_list":["post-174","post","type-post","status-publish","format-standard","hentry","category-geometry","tag-dot-product"],"_links":{"self":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/174","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=174"}],"version-history":[{"count":0,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=\/wp\/v2\/posts\/174\/revisions"}],"wp:attachment":[{"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thomas-jansen.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}