{"id":562,"date":"2020-02-29T15:53:51","date_gmt":"2020-02-29T15:53:51","guid":{"rendered":"https:\/\/www.parametriczoo.com\/?p=562"},"modified":"2020-03-20T22:40:51","modified_gmt":"2020-03-20T22:40:51","slug":"signed-distance-of-a-point-from-a-plane","status":"publish","type":"post","link":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/","title":{"rendered":"Signed distance of a point from a plane"},"content":{"rendered":"<p>[et_pb_section fb_built=&#8221;1&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_row custom_padding=&#8221;||0px|||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_text _builder_version=&#8221;3.22.7&#8243; custom_padding=&#8221;||13px|||&#8221;]<\/p>\n<p>Today I was looking at the <a href=\"https:\/\/www.revitapidocs.com\/2018.1\/802cc09b-d0a4-dfc5-8ca1-e8c5e8cd4ced.htm\">Project()<\/a> method in Revit API. The method signature offers a distance parameter which outputs the distance of the projected point to the input point.\u00a0<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;3.22.7&#8243; background_color=&#8221;#f2f2f2&#8243; border_width_all=&#8221;1px&#8221; border_color_all=&#8221;#d3d3d3&#8243; custom_margin=&#8221;-2px|||||&#8221; custom_padding=&#8221;11px|15px|0px|15px|false|true&#8221; global_module=&#8221;565&#8243; saved_tabs=&#8221;all&#8221;]<\/p>\n<pre><code><span class=\"keyword\">public<\/span> <span class=\"keyword\">void<\/span> <span class=\"identifier\">Project<\/span>(\n\t<a href=\"c2fd995c-95c0-58fb-f5de-f3246cbc5600.htm\">XYZ<\/a> <span class=\"parameter\">point<\/span>,\n\t<span class=\"keyword\">out<\/span> <a href=\"1724be37-059b-91ff-aa74-d1508082f76d.htm\">UV<\/a> <span class=\"parameter\">uv<\/span>,\n\t<span class=\"keyword\">out<\/span> <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/643eft0t\" target=\"_blank\" rel=\"noopener noreferrer\">double<\/a> <span class=\"parameter\">distance<\/span>\n)<\/code><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;3.22.7&#8243; min_height=&#8221;130px&#8221; custom_padding=&#8221;||0px|||&#8221;]<\/p>\n<p>\u00a0The value of distance parameter is always positive which means we have no clue if the point is above or below the plane. Apart from this issue , the method is implemented in Revit API 2018.1 and it is not available in earlier versions. In this post I discuss two different methods for finding the signed distance of a point from a plane, first using change of basis and trasformations and in the second method we use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dot_product\">dot product<\/a> which in my opinion it is the essence of linear algebra!\u00a0<\/p>\n<p>In order find the signed distance of point <em><strong>p<\/strong><\/em> from the given plane <em><b>Q\u00a0<\/b><\/em>we can simply evaluate the point with respect to the local coordinate system of the plane. This operation is called <strong>change of basis<\/strong>. Let us say the plane <strong><em>Q<\/em> <\/strong>is at origin <em><strong>O<\/strong> <\/em>with basis <strong><em>X<\/em><\/strong>,<strong><em>Y<\/em><\/strong> and <em><strong>Z<\/strong><\/em>, We can write the components of the plane <strong><em>Q<\/em><\/strong> in vector format :<\/p>\n<p>&nbsp;<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;0px|||||&#8221; custom_margin=&#8221;-2px|auto||auto||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;3_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/image004.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column type=&#8221;1_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/image006.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;1px||4px|||&#8221; custom_margin=&#8221;|auto|1px|auto||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>The transformation of any point from global coordinate system to the plane coordinate system can be define by the 4&#215;4\u00a0 matrix <em><strong>A<\/strong> <\/em>which is composed of the basis vectors of the plane and the origin point (translation part).<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/image002-1.png&#8221; align=&#8221;center&#8221; _builder_version=&#8221;3.22.7&#8243; width=&#8221;27%&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>The point <strong><em>p&#8217;<\/em><\/strong> is described in the plane local coordinate system, therefore by transforming <em><strong>p&#8217;<\/strong><\/em> to using plane transformation we obtain point <strong><em>p<\/em><\/strong> in global coordinate system. This operation can be reversed to find the point\u00a0<em><strong>p&#8217;<\/strong><\/em> which is the coordinates of point <em><strong>p<\/strong> <\/em>with resepct to the plane coordinate system.<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/image008-1.png&#8221; align=&#8221;center&#8221; _builder_version=&#8221;3.22.7&#8243; width=&#8221;31%&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>Below snipped code demonstrates the implementation of change of basis and extracts the <em><strong>Z<\/strong><\/em> coordinate of point p&#8217; as the signed distance of the point <em><strong>p<\/strong><\/em> with respect to the plane. Also note that we can output the projection point just by transforming the local projection of <strong><em>p&#8217;<\/em><\/strong> to the global coordsys.<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;3.22.7&#8243; background_color=&#8221;#f2f2f2&#8243; border_width_all=&#8221;1px&#8221; border_color_all=&#8221;#d3d3d3&#8243; custom_margin=&#8221;-2px|||||&#8221; custom_padding=&#8221;11px|15px|0px|15px|false|true&#8221; saved_tabs=&#8221;all&#8221;]<\/p>\n<pre style=\"font-family: Consolas; font-size: 13px; color: black; \"><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">        \/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">summary<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> return signed distance of point from the plane. <\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> If the point is above the plane (in positive side of the plane) <\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> the result is positive and if the point<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> is below the plane the result is negetive<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;\/<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">summary<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - attribute name\" style=\"color: gray;\"> name<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">=<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><span class=\"xml doc comment - text\" style=\"color: green;\">Input plane<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;\/<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - attribute name\" style=\"color: gray;\"> name<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">=<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">point<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><span class=\"xml doc comment - text\" style=\"color: green;\">Point to measure the distance from<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;\/<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - attribute name\" style=\"color: gray;\"> name<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">=<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">projection<\/span><span class=\"xml doc comment - attribute quotes\" style=\"color: gray;\">\"<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><span class=\"xml doc comment - text\" style=\"color: green;\">Projection of input point on this plane<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;\/<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">param<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"xml doc comment - delimiter\" style=\"color: gray;\">\/\/\/<\/span><span class=\"xml doc comment - text\" style=\"color: green;\"> <\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&lt;<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">returns<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;&lt;\/<\/span><span class=\"xml doc comment - name\" style=\"color: gray;\">returns<\/span><span class=\"xml doc comment - delimiter\" style=\"color: gray;\">&gt;<\/span><br \/>        <span class=\"keyword\" style=\"color: blue;\">public<\/span> <span class=\"keyword\" style=\"color: blue;\">static<\/span> <span class=\"keyword\" style=\"color: blue;\">double<\/span> <span class=\"extension method name - static symbol - (TRANSIENT)\" style=\"color: #74531f;\">DistanceTo<\/span> <span class=\"punctuation\">(<\/span><span class=\"keyword\" style=\"color: blue;\">this<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">Plane<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">plane<\/span><span class=\"punctuation\">,<\/span><span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">point<\/span><span class=\"punctuation\">,<\/span><span class=\"keyword\" style=\"color: blue;\">out<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">projection<\/span><span class=\"punctuation\">)<\/span><br \/>        <span class=\"punctuation\">{<\/span><br \/>            <span class=\"comment\" style=\"color: green;\">\/\/build a transformation matrix based on the plane coordinate system<\/span><br \/>            <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">Transform<\/span> <span class=\"local name\" style=\"color: #1f377f;\">tr<\/span> <span class=\"operator\">=<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">Transform<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - static symbol - (TRANSIENT)\" style=\"color: #74531f;\">CreateTranslation<\/span><span class=\"punctuation\">(<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Origin<\/span><span class=\"punctuation\">);<\/span> <br \/>            <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">tr<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">BasisX<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">XVec<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">Normalize<\/span><span class=\"punctuation\">();<\/span><br \/>            <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">tr<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">BasisY<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">YVec<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">Normalize<\/span><span class=\"punctuation\">()<\/span> <span class=\"punctuation\">;<\/span><br \/>            <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">tr<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">BasisZ<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Normal<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">Normalize<\/span><span class=\"punctuation\">();<\/span><br \/>            <span class=\"comment\" style=\"color: green;\">\/\/Find the local coordinates of the given point with resepct to plabe coordinate system<\/span><br \/>            <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span> <span class=\"local name\" style=\"color: #1f377f;\">local<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">tr<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Inverse<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">OfPoint<\/span><span class=\"punctuation\">(<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">point<\/span><span class=\"punctuation\">);<\/span><br \/>            <span class=\"comment\" style=\"color: green;\">\/\/project the local point to the XY plane (Z=0)<\/span><br \/>            <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">projection<\/span> <span class=\"operator\">=<\/span> <span class=\"keyword\" style=\"color: blue;\">new<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span><span class=\"punctuation\">(<\/span><span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">local<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">X<\/span><span class=\"punctuation\">,<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">local<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Y<\/span><span class=\"punctuation\">,<\/span> <span class=\"number\">0<\/span><span class=\"punctuation\">);<\/span><br \/>            <span class=\"comment\" style=\"color: green;\">\/\/ transform the projection back to the global coordSYS<\/span><br \/>            <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">projection<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">tr<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">OfPoint<\/span><span class=\"punctuation\">(<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">projection<\/span><span class=\"punctuation\">);<\/span><br \/>            <span class=\"comment\" style=\"color: green;\">\/\/The Z coordinate of the local point is the signed distance from the plane <\/span><br \/>            <span class=\"keyword - control\" style=\"color: #8f08c4;\">return<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">local<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Z<\/span><span class=\"punctuation\">;<\/span><br \/>        <span class=\"punctuation\">}<\/span><\/pre>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;3.22.7&#8243; custom_margin=&#8221;||5px|||&#8221;]<\/p>\n<p>Well, above is not really an elegant method!, my aim was to discuss a bit of change of basis which is very important topic. The distance of a point from a plane is simply calculated from the equation <em><strong>(5)<\/strong><\/em> in below.\u00a0 Let us assume plane <em><strong>Q<\/strong><\/em> with normal <em><strong>n<\/strong><\/em>\u00a0 and a point on plane <em><strong>p0<\/strong><\/em>\u00a0 and a point <em><strong>p<\/strong><\/em> outside the plane with its normal projection on plane<em><strong> p&#8217;<\/strong><\/em>.\u00a0<\/p>\n<p>[\/et_pb_text][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/sign-distane-to-plane.png&#8221; _builder_version=&#8221;3.22.7&#8243; custom_margin=&#8221;||4px|||&#8221;][\/et_pb_image][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>Starting from equation <strong><em>(1)<\/em><\/strong> which is simply sum of vectors and taking dot product of both sides we obtain equation <em><strong>(2)<\/strong><\/em>.\u00a0\u00a0<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image001-4.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image003-3.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;3px|||||&#8221; custom_margin=&#8221;|auto|-13px|auto||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>Equation <strong><em>(3)<\/em><\/strong> is obtained by expanding <em><strong>(2)<\/strong><\/em> and rewriting <em><strong>(p-p&#8217;).n<\/strong><\/em> as <em><strong>d*n<\/strong> <\/em>where<em><strong> d<\/strong><\/em> is the distance between the <em><strong>p<\/strong><\/em> and <em><strong>p&#8217;<\/strong><\/em> (Note if <em><strong>p<\/strong><\/em> is below the plane then <em><strong>d<\/strong><\/em> must be negative therefore <em><strong>d<\/strong><\/em> is signed distance).\u00a0Then we can write <em><strong>(4)<\/strong><\/em> by replacing<em><strong>\u00a0(p\u2080-p&#8217;).n<\/strong><\/em> with zero since two vectors are perpendicular and their dot product is zero.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;5px|||||&#8221; custom_margin=&#8221;|auto|-7px|auto||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image005-3.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image007-2.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;5px|||||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>Finally in we replace <em><strong>n.n <\/strong><\/em>by 1 since n is normal vector. Equation <strong><em>(5)<\/em><\/strong> gives us the signed distance from the plane and by moving the point <em><strong>p<\/strong><\/em> in opposite direction of plane normal <em><strong>(n)<\/strong><\/em> by the magnitude of d we obtain<em><strong> p&#8217;<\/strong><\/em> in equation<em><strong> (6)<\/strong><\/em><\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][et_pb_row custom_padding=&#8221;||8px|||&#8221; _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image009-3.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][et_pb_column type=&#8221;1_2&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_image src=&#8221;https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/03\/image011-2.png&#8221; _builder_version=&#8221;3.22.7&#8243;][\/et_pb_image][\/et_pb_column][\/et_pb_row][et_pb_row _builder_version=&#8221;3.22.7&#8243;][et_pb_column type=&#8221;4_4&#8243; _builder_version=&#8221;3.22.7&#8243;][et_pb_text _builder_version=&#8221;3.22.7&#8243;]<\/p>\n<p>Below is a simple and more elegant implementation of the same method.\u00a0<\/p>\n<p>[\/et_pb_text][et_pb_text _builder_version=&#8221;3.22.7&#8243; background_color=&#8221;#f2f2f2&#8243; border_width_all=&#8221;1px&#8221; border_color_all=&#8221;#d3d3d3&#8243; custom_margin=&#8221;-2px|||||&#8221; custom_padding=&#8221;11px|15px|0px|15px|false|true&#8221; saved_tabs=&#8221;all&#8221;]<\/p>\n<pre style=\"font-family: Consolas; font-size: 13px; color: black;\"><span class=\"keyword\" style=\"color: blue;\">public<\/span> <span class=\"keyword\" style=\"color: blue;\">static<\/span> <span class=\"keyword\" style=\"color: blue;\">double<\/span> <span class=\"ReSharper Dead Code - extension method name - static symbol - (TRANSIENT)\" style=\"color: #74531f;\">DistanceTo2<\/span><span class=\"punctuation\">(<\/span><span class=\"keyword\" style=\"color: blue;\">this<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">Plane<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">plane<\/span><span class=\"punctuation\">,<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">point<\/span><span class=\"punctuation\">,<\/span> <span class=\"keyword\" style=\"color: blue;\">out<\/span> <span class=\"class name - identifier - (TRANSIENT)\" style=\"color: #2b91af;\">XYZ<\/span> <span class=\"parameter name\" style=\"color: #1f377f;\">projection<\/span><span class=\"punctuation\">)<\/span><br \/><span class=\"punctuation\">{<\/span><br \/>    <span class=\"comment\" style=\"color: green;\">\/\/ signed distance from equation (5)<\/span><br \/>    <span class=\"keyword\" style=\"color: blue;\">double<\/span> <span class=\"local name\" style=\"color: #1f377f;\">d<\/span> <span class=\"operator\">=<\/span> <span class=\"punctuation\">(<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">point<\/span> <span class=\"operator - operator - overloaded - (TRANSIENT)\" style=\"color: #74531f;\">-<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Origin<\/span><span class=\"punctuation\">)<\/span><span class=\"operator\">.<\/span><span class=\"identifier - method name - (TRANSIENT)\" style=\"color: #74531f;\">DotProduct<\/span><span class=\"punctuation\">(<\/span><span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Normal<\/span><span class=\"punctuation\">);<\/span><br \/>    <span class=\"comment\" style=\"color: green;\">\/\/ the projection point from equation (6)<\/span><br \/>    <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">projection<\/span> <span class=\"operator\">=<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">point<\/span> <span class=\"operator - operator - overloaded - (TRANSIENT)\" style=\"color: #74531f;\">-<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">d<\/span> <span class=\"operator - operator - overloaded - (TRANSIENT)\" style=\"color: #74531f;\">*<\/span> <span class=\"identifier - parameter name - (TRANSIENT)\" style=\"color: #1f377f;\">plane<\/span><span class=\"operator\">.<\/span><span class=\"identifier - property name - (TRANSIENT)\">Normal<\/span><span class=\"punctuation\">;<\/span><br \/>    <span class=\"keyword - control\" style=\"color: #8f08c4;\">return<\/span> <span class=\"identifier - local name - (TRANSIENT)\" style=\"color: #1f377f;\">d<\/span><span class=\"punctuation\">;<\/span><br \/><span class=\"punctuation\">}<\/span><\/pre>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I was looking at the Project() method in Revit API. The method signature offers a distance parameter which outputs the distance of the projected point to the input point.\u00a0public void Project( XYZ point, out UV uv, out double distance ) \u00a0The value of distance parameter is always positive which means we have no clue [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":591,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":""},"categories":[45],"tags":[49,33,47],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Signed distance of a point from a plane - Parametric Zoo<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Signed distance of a point from a plane - Parametric Zoo\" \/>\n<meta property=\"og:description\" content=\"Today I was looking at the Project() method in Revit API. The method signature offers a distance parameter which outputs the distance of the projected point to the input point.\u00a0public void Project( XYZ point, out UV uv, out double distance ) \u00a0The value of distance parameter is always positive which means we have no clue [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/\" \/>\n<meta property=\"og:site_name\" content=\"Parametric Zoo\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-29T15:53:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-20T22:40:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1680\" \/>\n\t<meta property=\"og:image:height\" content=\"1300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"PARA\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PARA\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.parametriczoo.com\/#website\",\"url\":\"https:\/\/www.parametriczoo.com\/\",\"name\":\"Parametric Zoo\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.parametriczoo.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#primaryimage\",\"url\":\"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg\",\"contentUrl\":\"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg\",\"width\":1680,\"height\":1300},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/\",\"url\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/\",\"name\":\"Signed distance of a point from a plane - Parametric Zoo\",\"isPartOf\":{\"@id\":\"https:\/\/www.parametriczoo.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#primaryimage\"},\"datePublished\":\"2020-02-29T15:53:51+00:00\",\"dateModified\":\"2020-03-20T22:40:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.parametriczoo.com\/#\/schema\/person\/0368c6eb8bfe3a003504793be2a2e0e3\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.parametriczoo.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Signed distance of a point from a plane\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.parametriczoo.com\/#\/schema\/person\/0368c6eb8bfe3a003504793be2a2e0e3\",\"name\":\"PARA\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.parametriczoo.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2b2ff0ff40493545df12d0b31a504675?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2b2ff0ff40493545df12d0b31a504675?s=96&d=mm&r=g\",\"caption\":\"PARA\"},\"url\":\"https:\/\/www.parametriczoo.com\/index.php\/author\/para\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Signed distance of a point from a plane - Parametric Zoo","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/","og_locale":"en_US","og_type":"article","og_title":"Signed distance of a point from a plane - Parametric Zoo","og_description":"Today I was looking at the Project() method in Revit API. The method signature offers a distance parameter which outputs the distance of the projected point to the input point.\u00a0public void Project( XYZ point, out UV uv, out double distance ) \u00a0The value of distance parameter is always positive which means we have no clue [&hellip;]","og_url":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/","og_site_name":"Parametric Zoo","article_published_time":"2020-02-29T15:53:51+00:00","article_modified_time":"2020-03-20T22:40:51+00:00","og_image":[{"width":1680,"height":1300,"url":"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg","type":"image\/jpeg"}],"author":"PARA","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PARA","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.parametriczoo.com\/#website","url":"https:\/\/www.parametriczoo.com\/","name":"Parametric Zoo","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.parametriczoo.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#primaryimage","url":"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg","contentUrl":"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg","width":1680,"height":1300},{"@type":"WebPage","@id":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/","url":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/","name":"Signed distance of a point from a plane - Parametric Zoo","isPartOf":{"@id":"https:\/\/www.parametriczoo.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#primaryimage"},"datePublished":"2020-02-29T15:53:51+00:00","dateModified":"2020-03-20T22:40:51+00:00","author":{"@id":"https:\/\/www.parametriczoo.com\/#\/schema\/person\/0368c6eb8bfe3a003504793be2a2e0e3"},"breadcrumb":{"@id":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.parametriczoo.com\/index.php\/2020\/02\/29\/signed-distance-of-a-point-from-a-plane\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.parametriczoo.com\/"},{"@type":"ListItem","position":2,"name":"Signed distance of a point from a plane"}]},{"@type":"Person","@id":"https:\/\/www.parametriczoo.com\/#\/schema\/person\/0368c6eb8bfe3a003504793be2a2e0e3","name":"PARA","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.parametriczoo.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2b2ff0ff40493545df12d0b31a504675?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2b2ff0ff40493545df12d0b31a504675?s=96&d=mm&r=g","caption":"PARA"},"url":"https:\/\/www.parametriczoo.com\/index.php\/author\/para\/"}]}},"jetpack_featured_media_url":"https:\/\/www.parametriczoo.com\/wp-content\/uploads\/2020\/02\/distance-to-plabe.jpg","_links":{"self":[{"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/posts\/562"}],"collection":[{"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/comments?post=562"}],"version-history":[{"count":0,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/posts\/562\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/media\/591"}],"wp:attachment":[{"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/media?parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/categories?post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.parametriczoo.com\/index.php\/wp-json\/wp\/v2\/tags?post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}