In my work, I use rectangular surfaces in the 3D space as the separating entity between two subsets of points. I don't want these two subsets to influence each other in weighted averaging operations, so I place a rectangular dividend in-between. Let's define a rectangle by these variables:
- c : center of the rectangle
- u, v : normalized vectors that define the extent direction of the rectangle from the center
- eU, eV : extent values.
d = p - c;If I go deeper into this code, when I take the dot product of d with u and v, essentially I obtain the coordinate of the projection of p onto the plane that the rectangle lies on in terms of the rectangle's local coordinate system. Other absolute value stuff are there because I want the function to have a value of 0 inside the rectangle and a positive value outside of the rectangle. When I have the contour plot of this function with Mathematica, I obtain something like this:
dist = Abs[Dot[d, u]] - eu;
du = Abs[dist] + dist;
dist = Abs[Dot[d, v]] - ev;
dv = Abs[dist] + dist;
Return[Sqrt[du^2 + dv^2]];
Now, I need to combine this information with the distance of the point to the rectangle in the rectangle's normal direction. This is simply achieved by taking the dot product of the d vector with the normalized normal vector of the rectangle.
s = Abs[Dot[d, n]];This results in the 3D distance function of an arbitrary rectangle:
Return[Sqrt[(du^2 + dv^2) + s^2]];


No comments:
Post a Comment