3

I have a point in 3d space (x,y,z). I want to move radially outward from that point discretely (say for r=1 and r=2). In the x,y plane I can simply move outward by stepping ((x+r cos(theta)), (y+r sin(theta)), z) with r = 1 or 2 and theta varying every, say 10 degrees.

However, I am unsure how to describe this movement if I want to have lines moving outward on a tilted plane and step my lines within this plane.

I thought it would be just using spherical coordinates. But if I'm drawing lines from a center point using (x=rho sin phi cos theta, y=..., z=...) won't that form a cone rather than a circle tilted on a plane?

P.S. Will be implementing this in MATLAB

browser
  • 313
  • 1
  • 3
  • 12
  • you can define your lines in the XY plane (simpler starting definition), then rotate them as you tilt the plane (just a rotation operator to apply to your points). By the way, when you talk about 'tilting' the plane, you need to precise around which line/axis you want to perform the rotation. – Hoki Jan 23 '15 at 12:51

2 Answers2

1

How is your tilted plane defined?
Define it with base point P0 and two perpendicular unit vectors U and V. It is not hard to get this representation from any other. For example, if normal vector of your plane have angles ax, ay, az with axes OX, OY, OZ respectively, it's normalized form is N = (nx, ny, nz) = (Cos(ax), Cos(ay), Cos(az)). You can choose arbitrary vector U (lying in the plane) as described here, and find V vector as vector product V = U x N
Then needed points are:

P = P0 + U * R * Cos(Theta) + V * R * Sin(Theta)

Community
  • 1
  • 1
MBo
  • 77,366
  • 5
  • 53
  • 86
  • The plane isn't defined - I was hoping to define it by the angles with the axis in the stepping of my radial lines? So you are saying P0 would be my 3d center point (x,y,z). I'm still not sure about how I would get U and V? – browser Jan 23 '15 at 11:00
  • I'm basically trying to find the best plane so looping through a range of tilts. e.g. I create my lines in the x,y plane, then I want to tilt that plane (say 10 degrees) and draw lines out in that plane – browser Jan 23 '15 at 11:03
1

You could first make the coordinates going outwards from P0 and then rotate the coordinates using a rotation matrix.

So you take points P for all R's and thetas, as MBo pointed out:

P = [ P0x + R * cos(theta); P0y + R * sin(theta); 0 ]

Then you make a rotation matrix that rotates the XY plane with the angles you want

rotation matrices

If you multiply that with your coordinates you get the rotated coordinates. For example a 90 degree rotation about the Z axis for the point [1,0,0]:

enter image description here

However you probably want to rotate about the point P0 and not about the origin, then you have to make an affine matrix with the following translation:

tx = x- r00 * x - r01 * y - r02 * z

ty = y- r10 * x - r11 * y - r12 * z

tz = z- r20 * x - r21 * y - r22 * z

And then make an affine transformation matrix with T and R (designated as M in the figure, sorry):

affine matrix, M is the rotation matrix here

In this figure Q are the old coordinates and Q' the new coordinates.

I had a similar problem and used this answer and adjusted it to your problem:

%input point and rotated plane
p0 = [10;10;10;1]; % the last entry is your homogeneous dimension
r0 = [45,45,45]; r0 = r0*pi/180;

%rotation to plane
Rx=[1 0 0 0;
    0 cos(r0(1)) sin(r0(1)) 0;
    0 -sin(r0(1)) cos(r0(1)) 0;
    0 0 0 1];
Ry=[cos(r0(2)) 0 -sin(r0(2)) 0;
    0 1 0 0;
    sin(r0(2)) 0 cos(r0(2)) 0;
    0 0 0 1];
Rz=[cos(r0(3)) sin(r0(3)) 0 0;
    -sin(r0(3)) cos(r0(3)) 0 0;
    0 0 1 0;
    0 0 0 1];
R = Rz*Ry*Rx; A = R;
T = ( eye(3)-R(1:3,1:3) ) * p0(1:3); %calculate translation to rotate about the point P0
A(1:3,4) = T; % to rotate about the origin just leave out this line

%make coordinates for the points going outward from p0
nangles = 36; anglestep = 2*pi/nangles;
nradii = 2; radiistep = 1;

thetas = anglestep:anglestep:2*pi;
rs = radiistep:radiistep:nradii*radiistep;
npoints = nradii*nangles;

coordinates = zeros(4,npoints); curpoint = 0;
for itheta = 1:nangles; for iradius = 1:nradii; 
        curpoint = curpoint+1;
        coordinates(:, curpoint) = p0+rs(iradius)*[cos(thetas(itheta));sin(thetas(itheta));0;0];
end; end

coordinates_tilted = A*coordinates; %rotate the coordinates to the new plane

Which results in this figure:

figure;
scatter3(coordinates_tilted(1,:),coordinates_tilted(2,:),coordinates_tilted(3,:), 'MarkerEdgeColor',  'green')
hold on
scatter3(coordinates(1,:),coordinates(2,:),coordinates(3,:), 'MarkerEdgeColor',  'red')
legend('tilted', 'original')

original and tilted points

Or plot them as lines:

%or as lines
coorarray = reshape(coordinates, [4 nradii nangles]);
Xline = squeeze(coorarray(1,:,:));
Yline = squeeze(coorarray(2,:,:));
Zline = squeeze(coorarray(3,:,:));

coorarray_tilted = reshape(coordinates_tilted, [4 nradii nangles]);
Xline_tilted = squeeze(coorarray_tilted(1,:,:));
Yline_tilted = squeeze(coorarray_tilted(2,:,:));
Zline_tilted = squeeze(coorarray_tilted(3,:,:));

figure;
plot3(Xline,Yline,Zline, 'r');
hold on
plot3(Xline_tilted,Yline_tilted,Zline_tilted, 'g');
legend( 'original', 'tilted')

original and tilted as lines

Does this answer your question? These are now points at all multiples of 36 degree angles at a distance of one and two from point P0 in the plane that is tilted 45 degrees on all axes around the point P0. If you need individual 'pixels' to designate your line (so integer coordinates) you can round the coordinates and that would be sort of a nearest neighbour approach:

coordinates_tilted_nearest = round(coordinates_tilted);
Community
  • 1
  • 1
Leo
  • 1,757
  • 3
  • 20
  • 44
  • 1
    Sorry - just looking back at the code. The rotation matrices in the body of your text (which match other literature) and the matrices in your code seem to have an inversion of the negative signs on the sin terms. Is this a typo or am I missing something? – browser Jan 29 '15 at 10:16
  • 1
    Oh yeah you are right, they all turn clockwise instead of counterclocwise. Thats a typo. – Leo Jan 29 '15 at 15:22