Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 7 Jan, 2012 09:06:08

Message: 1 of 20

3-D Plane Intersection: using intersection as
x-axis for 2-D plots on each plane

How Can I do this in simple way?
I tried meshgrid but I can not do this.

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D

From: ImageAnalyst

Date: 7 Jan, 2012 14:47:11

Message: 2 of 20

On Jan 7, 4:06 am, "Sebastian " <sebastianpszczo...@gmail.com> wrote:
> 3-D Plane Intersection: using intersection as
> x-axis for 2-D plots on each plane
>
> How Can I do this in simple way?
> I tried meshgrid but I can not do this.

-----------------------------------------------
The intersection of a plane and a solid 3D object (array) is a 2D
planar array. How can a 2D array be used as an x-axis? An x-axis has
to be a 1-D array.

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 7 Jan, 2012 15:01:08

Message: 3 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <je91u0$2ld$1@newscl01ah.mathworks.com>...
> 3-D Plane Intersection: using intersection as
> x-axis for 2-D plots on each plane
>
> How Can I do this in simple way?
> I tried meshgrid but I can not do this.
================

Not sure exactly what you're doing, but if you have both an x-axis and a y-axis as 3D vectors, you can derive a 2D manifold of meshgrid samples in 3D space as follows:

[xCoeffs,yCoeffs]=meshgrid(1:Whatever,1:Whatever);

meshSamples= xCoeffs(:)*xaxis(:).' + yCoeffs(:)*yaxis(:).';

The rows of meshSamples are each the 3D coordinate of a point on the mesh.

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 7 Jan, 2012 15:09:08

Message: 4 of 20

"Matt J" wrote in message <je9mnk$112$1@newscl01ah.mathworks.com>...
>
> Not sure exactly what you're doing, but if you have both an x-axis and a y-axis as 3D vectors, you can derive a 2D manifold of meshgrid samples in 3D space as follows:
>
> [xCoeffs,yCoeffs]=meshgrid(1:Whatever,1:Whatever);
>
> meshSamples= xCoeffs(:)*xaxis(:).' + yCoeffs(:)*yaxis(:).';
>
> The rows of meshSamples are each the 3D coordinate of a point on the mesh.
=====================


Oh, and of course if the plane doesn't pass through the origin, you will need to add a 3D offset vector to all the rows of meshSamples, e.g., by doing

 meshSamples= bsxfun(@plus, meshSamples,offset(:).');

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Roger Stafford

Date: 7 Jan, 2012 19:19:08

Message: 5 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <je91u0$2ld$1@newscl01ah.mathworks.com>...
> 3-D Plane Intersection: using intersection as
> x-axis for 2-D plots on each plane
>
> How Can I do this in simple way?
> I tried meshgrid but I can not do this.
- - - - - - - - - -
  Let's see if I can successfully interpret what you are saying, Sebastian. You have somehow defined two intersecting planes in three-dimensional space. Probably you have a set of points identified on each plane. You wish to plot each of these sets in a two-dimensional plot on each of the planes using as a new x-axis the line of intersection of the planes. Is that what you are asking?

  Of course the immediate question that occurs is where the new origin is to be located along the line of intersection. A natural choice would be the orthogonal projection of the original 3D origin onto that line. There is also the question of which of two directions should the two respective y-axes point - that is, which side of each of the planes should our points of view be from in the 2D plots?

  There is also the possibility that you actually have only one set of 3D points and two planes defined, and that you want to orthogonally project those points onto each of the planes and then prepare a 2D plot of those projected points as they would appear with new x and y axes within the respective planes using the intersection line as x-axis.

  Before we go any further in this problem it would be best if you would tell in much greater detail just what it is you are asking here. That is important in avoiding a waste of other people's time working out explanations that are not pertinent to your needs.

Roger Stafford

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 7 Jan, 2012 19:45:08

Message: 6 of 20

"Roger Stafford" wrote in message <jea5rc$di8$1@newscl01ah.mathworks.com>...
> "Sebastian " <sebastianpszczolka@gmail.com> wrote in message <je91u0$2ld$1@newscl01ah.mathworks.com>...
> > 3-D Plane Intersection: using intersection as
> > x-axis for 2-D plots on each plane
> >
> > How Can I do this in simple way?
> > I tried meshgrid but I can not do this.
> - - - - - - - - - -
> Let's see if I can successfully interpret what you are saying, Sebastian. You have somehow defined two intersecting planes in three-dimensional space. Probably you have a set of points identified on each plane. You wish to plot each of these sets in a two-dimensional plot on each of the planes using as a new x-axis the line of intersection of the planes. Is that what you are asking?
>
> Of course the immediate question that occurs is where the new origin is to be located along the line of intersection. A natural choice would be the orthogonal projection of the original 3D origin onto that line. There is also the question of which of two directions should the two respective y-axes point - that is, which side of each of the planes should our points of view be from in the 2D plots?
>
> There is also the possibility that you actually have only one set of 3D points and two planes defined, and that you want to orthogonally project those points onto each of the planes and then prepare a 2D plot of those projected points as they would appear with new x and y axes within the respective planes using the intersection line as x-axis.
>
> Before we go any further in this problem it would be best if you would tell in much greater detail just what it is you are asking here. That is important in avoiding a waste of other people's time working out explanations that are not pertinent to your needs.
>
> Roger Stafford


You are absolutley right I will show you what I have already done:
There is fucntion which calculate point for 2 planes from normal vector and point on planes.
<code>
function [x1,y1,z1,x2,y2,z2]=calculateplanes(obj)
            point = [obj.A1(1),obj.A1(2),obj.A1(3)];
            normal = [obj.N1(1),obj.N1(2),obj.N1(3)];
             
            %# a plane is a*x+b*y+c*z+d=0
            %# [a,b,c] is the normal. Thus, we have to calculate
            %# d and we're set
            d = -point*normal'; %'# dot product for less typing
             
            %# create x,y
            [xx,yy]=ndgrid(1:10,1:10);
             
            %# calculate corresponding z
            z1 = (-normal(1)*xx - normal(2)*yy - d)/normal(3);
            x1=xx;
            y1=yy;
             
            point = [obj.A2(1),obj.A2(2),obj.A2(3)];
            normal = [obj.N2(1),obj.N2(2),obj.N2(3)];
             
            %# a plane is a*x+b*y+c*z+d=0
            %# [a,b,c] is the normal. Thus, we have to calculate
            %# d and we're set
            d = -point*normal'; %'# dot product for less typing
             
            %# create x,y
            [xx,yy]=ndgrid(1:10,1:10);
             
            %# calculate corresponding z
            z2 = (-normal(1)*xx - normal(2)*yy - d)/normal(3);
            x2=xx;
            y2=yy;
           
        end
</code>

There is function which calculate intersection beetwen 2 planes and it gives me point on straight and direction vector but I do not know how to draw any function on each of plane. Can You help me with this and check my code beacause i do not know if it is the best way to achive ma object. I draw planes using surf(x1,y1,z1) hold on surf(x2,y2,z2)
 function [P,N,check]=plane_intersect(obj)
            P=[0 0 0];
            N=cross(obj.N1,obj.N2);
             
            if norm(N) < 10^-7 % Plane 1 and Plane 2 are near parallel
                V=obj.A1-obj.A2;
                if (dot(obj.N1,V) == 0)
                    check=1; % Plane 1 and Plane 2 coincide
                    return
                else
                    check=0; %Plane 1 and Plane 2 are disjoint
                    return
                end
            end
            check=2;
            maxc=find(abs(N)==max(abs(N)));
            d1 = -dot(obj.N1,obj.A1); %the constants in the Plane 1 equations
            d2 = -dot(obj.N2, obj.A2); %the constants in the Plane 2 equations
            switch maxc
                case 1 % intersect with x=0
                    P(1)= 0;
                    P(2) = (d2*obj.N1(3) - d1*obj.N2(3))/ N(1);
                    P(3) = (d1*obj.N2(2) - d2*obj.N1(2))/ N(1);
                case 2 %intersect with y=0
                    P(1) = (d1*obj.N2(3) - d2*obj.N1(3))/ N(2);
                    P(2) = 0;
                    P(3) = (d2*obj.N1(1) - d1*obj.N2(1))/ N(2);
                case 3 %intersect with z=0
                    P(1) = (d2*obj.N1(2) - d1*obj.N2(2))/ N(3);
                    P(2) = (d1*obj.N2(1) - d2*obj.N1(1))/ N(3);
                    P(3) = 0;
            end
        end

Thank you a lot

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 7 Jan, 2012 19:49:09

Message: 7 of 20

"Roger Stafford" wrote in message <jea5rc$di8$1@newscl01ah.mathworks.com>...
> "Sebastian " <sebastianpszczolka@gmail.com> wrote in message <je91u0$2ld$1@newscl01ah.mathworks.com>...
> > 3-D Plane Intersection: using intersection as
> > x-axis for 2-D plots on each plane
> >
> > How Can I do this in simple way?
> > I tried meshgrid but I can not do this.
> - - - - - - - - - -
> Let's see if I can successfully interpret what you are saying, Sebastian. You have somehow defined two intersecting planes in three-dimensional space. Probably you have a set of points identified on each plane. You wish to plot each of these sets in a two-dimensional plot on each of the planes using as a new x-axis the line of intersection of the planes. Is that what you are asking?
>
> Of course the immediate question that occurs is where the new origin is to be located along the line of intersection. A natural choice would be the orthogonal projection of the original 3D origin onto that line. There is also the question of which of two directions should the two respective y-axes point - that is, which side of each of the planes should our points of view be from in the 2D plots?
>
> There is also the possibility that you actually have only one set of 3D points and two planes defined, and that you want to orthogonally project those points onto each of the planes and then prepare a 2D plot of those projected points as they would appear with new x and y axes within the respective planes using the intersection line as x-axis.
>
> Before we go any further in this problem it would be best if you would tell in much greater detail just what it is you are asking here. That is important in avoiding a waste of other people's time working out explanations that are not pertinent to your needs.
>
> Roger Stafford


You are absolutley right I will show you what I have already done:
There is fucntion which calculate point for 2 planes from normal vector and point on planes.
<code>
function [x1,y1,z1,x2,y2,z2]=calculateplanes(obj)
            point = [obj.A1(1),obj.A1(2),obj.A1(3)];
            normal = [obj.N1(1),obj.N1(2),obj.N1(3)];
             
            %# a plane is a*x+b*y+c*z+d=0
            %# [a,b,c] is the normal. Thus, we have to calculate
            %# d and we're set
            d = -point*normal'; %'# dot product for less typing
             
            %# create x,y
            [xx,yy]=ndgrid(1:10,1:10);
             
            %# calculate corresponding z
            z1 = (-normal(1)*xx - normal(2)*yy - d)/normal(3);
            x1=xx;
            y1=yy;
             
            point = [obj.A2(1),obj.A2(2),obj.A2(3)];
            normal = [obj.N2(1),obj.N2(2),obj.N2(3)];
             
            %# a plane is a*x+b*y+c*z+d=0
            %# [a,b,c] is the normal. Thus, we have to calculate
            %# d and we're set
            d = -point*normal'; %'# dot product for less typing
             
            %# create x,y
            [xx,yy]=ndgrid(1:10,1:10);
             
            %# calculate corresponding z
            z2 = (-normal(1)*xx - normal(2)*yy - d)/normal(3);
            x2=xx;
            y2=yy;
           
        end
</code>

There is function which calculate intersection beetwen 2 planes and it gives me point on straight and direction vector but I do not know how to draw any function on each of plane. Can You help me with this and check my code beacause i do not know if it is the best way to achive ma object. I draw planes using surf(x1,y1,z1) hold on surf(x2,y2,z2)
 function [P,N,check]=plane_intersect(obj)
            P=[0 0 0];
            N=cross(obj.N1,obj.N2);
             
            if norm(N) < 10^-7 % Plane 1 and Plane 2 are near parallel
                V=obj.A1-obj.A2;
                if (dot(obj.N1,V) == 0)
                    check=1; % Plane 1 and Plane 2 coincide
                    return
                else
                    check=0; %Plane 1 and Plane 2 are disjoint
                    return
                end
            end
            check=2;
            maxc=find(abs(N)==max(abs(N)));
            d1 = -dot(obj.N1,obj.A1); %the constants in the Plane 1 equations
            d2 = -dot(obj.N2, obj.A2); %the constants in the Plane 2 equations
            switch maxc
                case 1 % intersect with x=0
                    P(1)= 0;
                    P(2) = (d2*obj.N1(3) - d1*obj.N2(3))/ N(1);
                    P(3) = (d1*obj.N2(2) - d2*obj.N1(2))/ N(1);
                case 2 %intersect with y=0
                    P(1) = (d1*obj.N2(3) - d2*obj.N1(3))/ N(2);
                    P(2) = 0;
                    P(3) = (d2*obj.N1(1) - d1*obj.N2(1))/ N(2);
                case 3 %intersect with z=0
                    P(1) = (d2*obj.N1(2) - d1*obj.N2(2))/ N(3);
                    P(2) = (d1*obj.N2(1) - d2*obj.N1(1))/ N(3);
                    P(3) = 0;
            end
        end

Thank you a lot

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Roger Stafford

Date: 7 Jan, 2012 22:08:08

Message: 8 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jea7jl$ifo$1@newscl01ah.mathworks.com>...
> You are absolutley right I will show you what I have already done: ......
- - - - - - - - - - -
  You've shown us code for determining a mesh of points in 3D projected vertically from the x-y plane into each of the planes and how you find those planes' line of intersection, but you haven't answered the questions as to 1) where on this line of intersection the new 2D origin is to be located, 2) in which direction along this line should be the positive x-axis, and 3) in which of two possible directions on each plane are to be the new positive y-axes. No doubt you can devise some scheme in terms of the cross product of the normals to the planes. You need to know all of this to exhibit these points in 2D plots.

  Instead of starting with an entire mesh of points on the original 3D x-y plane, why don't you just ask about determining how a single point (x,y,z) in 3D known to be on one of the planes is transformed into (x,y) coordinates on that plane in new 2D coordinates, (given the two planes and the answers to 1, 2, and 3 above?)

Roger Stafford

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 7 Jan, 2012 22:39:09

Message: 9 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jea7jl$ifo$1@newscl01ah.mathworks.com>...
>
> There is function which calculate intersection beetwen 2 planes and it gives me point on straight and direction vector but I do not know how to draw any function on each of plane.
===================

You need to clarify what it means to "draw any function on each of plane". If you mean you want an image (i.e. a 2D function) displayed on the surface of a plane in 3D, then maybe this is what you want:

http://www.mathworks.com/matlabcentral/fileexchange/28581-imsurf-3d-images

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 8 Jan, 2012 09:13:08

Message: 10 of 20

It will be OK if firstly i can draw cosinus fucntion on plane definied by me.
How to draw plot on planes defineid by me and drew by surf

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 8 Jan, 2012 11:14:08

Message: 11 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jebmn4$1g1$1@newscl01ah.mathworks.com>...
> It will be OK if firstly i can draw cosinus fucntion on plane definied by me.
> How to draw plot on planes defineid by me and drew by surf
I want to plot any function on planes definied like normal vector and point.
How Can I do this because it will be a little step to my object.
I tried using
tri1 = delaunay(x1,y1);
plot(x1,y1,'Color','red');
tri2 = delaunay(x,y);
hold on
plot(x,y,'Color','green');


trisurf(tri1, x1, y1, z1,'FaceColor','blue');
trisurf(tri1, x, y, z,'FaceColor','blue');

but it doesn't work.
Thank You

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 8 Jan, 2012 14:01:08

Message: 12 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jebmn4$1g1$1@newscl01ah.mathworks.com>...
> It will be OK if firstly i can draw cosinus fucntion on plane definied by me.
> How to draw plot on planes defineid by me and drew by surf
===============

It's still a bit unclear to me why why you're turning to surface plotting commands when the thing you want to create (a plot of the cosine function) is a 1D space curve, not a 2D surface.

What about the following? It is a cosine curve occupying the plane spanned by xaxis and yaxis. How is this different from what you want? Note that you could also use PLOT3 instead of EZPLOT3.

 
xaxis=[-1 1 0]/sqrt(2);
yaxis=[0 0 1];

funx=@(t) t*xaxis(1)+cos(t)*yaxis(1);
funy=@(t) t*xaxis(2)+cos(t)*yaxis(2);
funz=@(t) t*xaxis(3)+cos(t)*yaxis(3);

ezplot3(funx,funy,funz,[-4*pi, 4*pi]); title ''

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 8 Jan, 2012 19:01:08

Message: 13 of 20

Thank for answer,
My task is from normal vector and point i should plot one plane. From another normal vector and point i should plot another plane on their intersection is my new x-axis and i should plot on one plane cosinus and on another sinus. I have plotted two intersection plane and I have equation for straight its direction vecotr and point but I do not know how to draw any function eg. sinus on this planes. Can someone help me?
Thank You

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Roger Stafford

Date: 8 Jan, 2012 22:54:08

Message: 14 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jecp5k$8ft$1@newscl01ah.mathworks.com>...
> My task is from normal vector and point i should plot one plane. From another normal vector and point i should plot another plane on their intersection is my new x-axis and i should plot on one plane cosinus and on another sinus. I have plotted two intersection plane and I have equation for straight its direction vecotr and point but I do not know how to draw any function eg. sinus on this planes. Can someone help me?
> Thank You
- - - - - - - - - -
  As nearly as I can understand your request, your problem can be divided into three basic tasks. First, you are given two point/normal pairs which each define a plane in three dimensions, and you must determine some particular point on their line of intersection to be a new origin. As you may recall, I suggested choosing it as the orthogonal projection of the old origin onto that intersection line.

  Second, you must determine two new sets of axes using this new origin in which the x-axis is along the planes' intersection for both new coordinates, the z-axes are along the respective positive normal directions, and the y-axes form the usual right-hand systems lying within the planes and orthogonal to the intersection line.

  Third, you apparently have the need to transform from new coordinates to old, and possibly old coordinates to new ones, for each of the two planes' systems.

  For the first, call (as you did) the two normals N1 and N2, and the two corresponding points lying somewhere in the planes, A1 and A2. In the absence of any other criterion, let P0 be, as suggested, the orthogonal projection of the origin onto the planes' intersection line. Then we must have the three equations for P0 = (x0,y0,z0):

 dot(N1,P0) = dot(N1,A1)
 dot(N2,P0) = dot(N2,A2)
 dot(cross(N1,N2),P0) = 0

which represent three equations in the three unknowns, x0, y0, and z0. As can be demonstrated, the solution is:

 P0 = (cross(N2,cross(N1,N2))*dot(N1,A1)-cross(N1,cross(N1,N2))*dot(N2,A2)) / ...
        dot(cross(N1,N2),cross(N1,N2));

(Note that this is valid whether N1 and N2 have been normalized or not.)

  That establishes a new origin for both new coordinate systems as a point on the planes' line of intersection, namely the closest point to the old origin.

  For the second task we can choose cross(N1,N2) to point in the direction of the new positive x-axis common to both new coordinate systems. Define the unit vector

 u1 = cross(N1,N2)/norm(cross(N1,N2));

which will be a unit vector along the new x-axis. Then define a unit vector w1, orthogonal to it as:

 w1 = N1/norm(N1);

This will be the new z-axis for the first plane. It points along the normal to the plane. Finally define

 v1 = cross(w1,u1);

and this will be the new y-axis of the plane lying in that plane. The triple u1,v1,w1 constitutes a right-hand system of orthogonal unit vectors oriented in relation to the first plane.

  This can be repeated with the second plane to form u2, v2, and w2 where u1 and u2 are the same, and we again have an orthonormal set of vectors for the second plane.

  For the third task using the first plane we want to establish a transformation between the original set of coordinates and a new set relative to u1,v1,w1. Let Q1 = (X1,Y1,Z1) be coordinates relative to the (u1,v1,w1) set of an arbitrary point P = (x,y,z) (relative to the original coordinate system.) We must have the equality

 P = u1*X1+v1*Y1+w1*Z1 + P0

If we agree to make u1, v1, and w1 row vectors and P and Q column vectors, we can write the matlab expression

 T1 = [u1;v1;w1];
 P = bsxfun(@plus,T1*Q1,P0);

The 'bsxfun' function is used here to make this valid even if P and Q1 are 3 by n matrices for n points in which each column has the three coordinates of the corresponding point.

  To transform in the opposite direction from P to Q1, it is simply

 Q1 = T1'*bsxfun(@minus,P,P0);

That is true because T1 is inherently a unitary matrix and its inverse is the same as its (conjugate) transpose.

  Similar statements can be made for a 3 by 3 matrix T2 with respect to the second plane's coordinate system.

  (It should be noted that all this is analogous to the problem of rotating and translating solid bodies within a fixed coordinate system. The T matrices become the rotation matrices.)

  Now with all these methods you have the means to transform two-dimensional plots made for X1,Y1,Z1 coordinates, assuming Z1 is a constant zero, and transforming them into the original x,y,z coordinates which you can plot using 'plot3' where these points will all show up as lying in the given plane. If you do the same with X2,Y2,Z2 coordinate sets, both sets can be displayed on the 'plot3' plot together and you will observe the points lying in two planes there. As pointed out above, you can use entire 3 by n matrices to make transformations of plots in a single line for these transformations.

Roger Stafford

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 9 Jan, 2012 07:27:08

Message: 15 of 20

"Roger Stafford" wrote in message <jed6qg$grf$1@newscl01ah.mathworks.com>...
> "Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jecp5k$8ft$1@newscl01ah.mathworks.com>...
> > My task is from normal vector and point i should plot one plane. From another normal vector and point i should plot another plane on their intersection is my new x-axis and i should plot on one plane cosinus and on another sinus. I have plotted two intersection plane and I have equation for straight its direction vecotr and point but I do not know how to draw any function eg. sinus on this planes. Can someone help me?
> > Thank You
> - - - - - - - - - -
> As nearly as I can understand your request, your problem can be divided into three basic tasks. First, you are given two point/normal pairs which each define a plane in three dimensions, and you must determine some particular point on their line of intersection to be a new origin. As you may recall, I suggested choosing it as the orthogonal projection of the old origin onto that intersection line.
>
> Second, you must determine two new sets of axes using this new origin in which the x-axis is along the planes' intersection for both new coordinates, the z-axes are along the respective positive normal directions, and the y-axes form the usual right-hand systems lying within the planes and orthogonal to the intersection line.
>
> Third, you apparently have the need to transform from new coordinates to old, and possibly old coordinates to new ones, for each of the two planes' systems.
>
> For the first, call (as you did) the two normals N1 and N2, and the two corresponding points lying somewhere in the planes, A1 and A2. In the absence of any other criterion, let P0 be, as suggested, the orthogonal projection of the origin onto the planes' intersection line. Then we must have the three equations for P0 = (x0,y0,z0):
>
> dot(N1,P0) = dot(N1,A1)
> dot(N2,P0) = dot(N2,A2)
> dot(cross(N1,N2),P0) = 0
>
> which represent three equations in the three unknowns, x0, y0, and z0. As can be demonstrated, the solution is:
>
> P0 = (cross(N2,cross(N1,N2))*dot(N1,A1)-cross(N1,cross(N1,N2))*dot(N2,A2)) / ...
> dot(cross(N1,N2),cross(N1,N2));
>
> (Note that this is valid whether N1 and N2 have been normalized or not.)
>
> That establishes a new origin for both new coordinate systems as a point on the planes' line of intersection, namely the closest point to the old origin.
>
> For the second task we can choose cross(N1,N2) to point in the direction of the new positive x-axis common to both new coordinate systems. Define the unit vector
>
> u1 = cross(N1,N2)/norm(cross(N1,N2));
>
> which will be a unit vector along the new x-axis. Then define a unit vector w1, orthogonal to it as:
>
> w1 = N1/norm(N1);
>
> This will be the new z-axis for the first plane. It points along the normal to the plane. Finally define
>
> v1 = cross(w1,u1);
>
> and this will be the new y-axis of the plane lying in that plane. The triple u1,v1,w1 constitutes a right-hand system of orthogonal unit vectors oriented in relation to the first plane.
>
> This can be repeated with the second plane to form u2, v2, and w2 where u1 and u2 are the same, and we again have an orthonormal set of vectors for the second plane.
>
> For the third task using the first plane we want to establish a transformation between the original set of coordinates and a new set relative to u1,v1,w1. Let Q1 = (X1,Y1,Z1) be coordinates relative to the (u1,v1,w1) set of an arbitrary point P = (x,y,z) (relative to the original coordinate system.) We must have the equality
>
> P = u1*X1+v1*Y1+w1*Z1 + P0
>
> If we agree to make u1, v1, and w1 row vectors and P and Q column vectors, we can write the matlab expression
>
> T1 = [u1;v1;w1];
> P = bsxfun(@plus,T1*Q1,P0);
>
> The 'bsxfun' function is used here to make this valid even if P and Q1 are 3 by n matrices for n points in which each column has the three coordinates of the corresponding point.
>
> To transform in the opposite direction from P to Q1, it is simply
>
> Q1 = T1'*bsxfun(@minus,P,P0);
>
> That is true because T1 is inherently a unitary matrix and its inverse is the same as its (conjugate) transpose.
>
> Similar statements can be made for a 3 by 3 matrix T2 with respect to the second plane's coordinate system.
>
> (It should be noted that all this is analogous to the problem of rotating and translating solid bodies within a fixed coordinate system. The T matrices become the rotation matrices.)
>
> Now with all these methods you have the means to transform two-dimensional plots made for X1,Y1,Z1 coordinates, assuming Z1 is a constant zero, and transforming them into the original x,y,z coordinates which you can plot using 'plot3' where these points will all show up as lying in the given plane. If you do the same with X2,Y2,Z2 coordinate sets, both sets can be displayed on the 'plot3' plot together and you will observe the points lying in two planes there. As pointed out above, you can use entire 3 by n matrices to make transformations of plots in a single line for these transformations.
>
> Roger Stafford


Thank you a lot. It is very helpful to understand how to do this.
I am new with that problem Can you give me simple example how to use this code because I tried did this in my way and I failed.
Thank You a lot.

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 9 Jan, 2012 12:21:08

Message: 16 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jecp5k$8ft$1@newscl01ah.mathworks.com>...
> Thank for answer,
> My task is from normal vector and point i should plot one plane. From another normal vector and point i should plot another plane on their intersection is my new x-axis and i should plot on one plane cosinus and on another sinus. I have plotted two intersection plane and I have equation for straight its direction vecotr and point but I do not know how to draw any function eg. sinus on this planes. Can someone help me?
====================

But I gave you an example of how to do exactly that in my last post...

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 9 Jan, 2012 12:44:09

Message: 17 of 20

"Matt J" wrote in message <jeem3k$18f$1@newscl01ah.mathworks.com>...
> "Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jecp5k$8ft$1@newscl01ah.mathworks.com>...
> > Thank for answer,
> > My task is from normal vector and point i should plot one plane. From another normal vector and point i should plot another plane on their intersection is my new x-axis and i should plot on one plane cosinus and on another sinus. I have plotted two intersection plane and I have equation for straight its direction vecotr and point but I do not know how to draw any function eg. sinus on this planes. Can someone help me?
> ====================
>
> But I gave you an example of how to do exactly that in my last post...

Thank you very much but Can You explain me that statment because I think it is not complete:
P0 = (cross(N2,cross(N1,N2))*dot(N1,A1)-cross(N1,cross(N1,N2))*dot(N2,A2)) / ...
dot(cross(N1,N2),cross(N1,N2)

Thank a lot

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Matt J

Date: 9 Jan, 2012 14:43:08

Message: 18 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jeenep$53k$1@newscl01ah.mathworks.com>...
>
> >
> > But I gave you an example of how to do exactly that in my last post...
>
> Thank you very much but Can You explain me that statment because I think it is not complete:
> P0 = (cross(N2,cross(N1,N2))*dot(N1,A1)-cross(N1,cross(N1,N2))*dot(N2,A2)) / ...
> dot(cross(N1,N2),cross(N1,N2)
===============


I never made a statement like that. Roger did.

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Roger Stafford

Date: 9 Jan, 2012 18:19:09

Message: 19 of 20

"Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jee4sc$bnd$1@newscl01ah.mathworks.com>...
> Thank you a lot. It is very helpful to understand how to do this.
> I am new with that problem Can you give me simple example how to use this code because I tried did this in my way and I failed.
> Thank You a lot.
- - - - - - - - -
  Sebastian, I have a correction to make in yesterday's explanation. Where I said "make u1, v1, and w1 row vectors" and "T1=[u1;v1;w1];" I should have said:

  "If we agree to make u1, v1, w1, P, and Q all column vectors, we can write the matlab expression

 T1 = [u1,v1,w1];"

My previous T1 was the inverse of what it should have been. My apologies.

  As to your question about the formula for P0, what is the problem you have with it? I did test it carefully and it is correct. It consists of a numerator which is the difference between two vectors, and a scalar in the denominator. In matlab it would be more efficient to write it like this:

 t = cross(N1,N2);
 P0 = (cross(N2,t)*dot(N1,A1)-cross(N1,t)*dot(N2,A2))/dot(t,t);

It is easy to see that this satisfies the three required equations.

  You have asked for an example of this. Suppose you wish to exhibit, three dimensionally, a plot of Y1 = sin(X1) for 0 <= X1 <= 2*pi on plane #1. I'll generate two planes randomly.

 N1 = randn(3,1); A1 = randn(3,1); % The first plane
 N2 = randn(3,1); A2 = randn(3,1); % The second plane
 n = 200;
 X1 = linspace(0,2*pi,n);
 Y1 = sin(X1); % The sine function on plane 1
 Z1 = zeros(1,n); % Place it on the plane
 Q1 = [X1;Y1;Z1];
 
 t = cross(N1,N2);
 P0 = (cross(N2,t)*dot(N1,A1)-cross(N1,t)*dot(N2,A2))/dot(t,t);
 u1 = t/norm(t); % Get three orthogonal unit vectors
 w1 = N1/norm(N1);
 v1 = cross(w1,u1);
 T1 = [u1,v1,w1]; % Prepare the transformation matrix
 P = bsxfun(@plus,T1*Q1,P0); % Sine curve in three dimensions
 plot3(P(1,:),P(2,:),P(3,:)) % Plot it
 
  (Note that instead of troubling to generate the zeros in Z1, you could just as well eliminate the third column of T1 and the third row of Q1.)

Roger Stafford

Subject: 3-D Plane Intersection: using intersection as x-axis for 2-D plots on each plane

From: Sebastian

Date: 9 Jan, 2012 20:39:09

Message: 20 of 20

"Roger Stafford" wrote in message <jefb2t$g55$1@newscl01ah.mathworks.com>...
> "Sebastian " <sebastianpszczolka@gmail.com> wrote in message <jee4sc$bnd$1@newscl01ah.mathworks.com>...
> > Thank you a lot. It is very helpful to understand how to do this.
> > I am new with that problem Can you give me simple example how to use this code because I tried did this in my way and I failed.
> > Thank You a lot.
> - - - - - - - - -
> Sebastian, I have a correction to make in yesterday's explanation. Where I said "make u1, v1, and w1 row vectors" and "T1=[u1;v1;w1];" I should have said:
>
> "If we agree to make u1, v1, w1, P, and Q all column vectors, we can write the matlab expression
>
> T1 = [u1,v1,w1];"
>
> My previous T1 was the inverse of what it should have been. My apologies.
>
> As to your question about the formula for P0, what is the problem you have with it? I did test it carefully and it is correct. It consists of a numerator which is the difference between two vectors, and a scalar in the denominator. In matlab it would be more efficient to write it like this:
>
> t = cross(N1,N2);
> P0 = (cross(N2,t)*dot(N1,A1)-cross(N1,t)*dot(N2,A2))/dot(t,t);
>
> It is easy to see that this satisfies the three required equations.
>
> You have asked for an example of this. Suppose you wish to exhibit, three dimensionally, a plot of Y1 = sin(X1) for 0 <= X1 <= 2*pi on plane #1. I'll generate two planes randomly.
>
> N1 = randn(3,1); A1 = randn(3,1); % The first plane
> N2 = randn(3,1); A2 = randn(3,1); % The second plane
> n = 200;
> X1 = linspace(0,2*pi,n);
> Y1 = sin(X1); % The sine function on plane 1
> Z1 = zeros(1,n); % Place it on the plane
> Q1 = [X1;Y1;Z1];
>
> t = cross(N1,N2);
> P0 = (cross(N2,t)*dot(N1,A1)-cross(N1,t)*dot(N2,A2))/dot(t,t);
> u1 = t/norm(t); % Get three orthogonal unit vectors
> w1 = N1/norm(N1);
> v1 = cross(w1,u1);
> T1 = [u1,v1,w1]; % Prepare the transformation matrix
> P = bsxfun(@plus,T1*Q1,P0); % Sine curve in three dimensions
> plot3(P(1,:),P(2,:),P(3,:)) % Plot it
>
> (Note that instead of troubling to generate the zeros in Z1, you could just as well eliminate the third column of T1 and the third row of Q1.)
>
> Roger Stafford


Thank you it is great

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us