Help with declaring half sphere with point, direction vector

10 views (last 30 days)
Brian on 12 Nov 2015
Commented: Brian on 12 Nov 2015
Hello, thanks for reading this,
I was wondering how I could create a half sphere by a single point (which is the center), and radius (which is given by the length of a direction vector). This part is relatively easy, I can use spherical coordinates to get this to work.
What I'm having problems with is getting a half sphere that faces the orientation I want on a point I want (that's why I included a direction vector and point). See this for a depiction of what I mean.
So, if I'm using spherical coordinates, I want the elevation and azimuth to range from 0:pi, but I want to rotate it slightly to match a direction vector, then I want to translate the half sphere so that the center is at the point I declare.
My prototype code is this: % Plot half sphere, V1 is direction vector, pt1 = sample point: pt1 = [15 10 2]; pt2 = [10 5 6]; V1 = pt2 - pt1;
[theta_rot,phi_rot,r] = cart2sph(V1(1), V1(2), V1(3));
theta=linspace(0,pi,40); phi=linspace(0,pi,40);
x=r*sin(phi).*cos(theta) + pt1(1);
y=r*sin(phi).*sin(theta) + pt1(2);
z=r*cos(phi) + pt1(3);
hold on
plot3([pt1(1) pt2(1)], ...
[pt1(2) pt2(2)], ...
[pt1(3) pt2(3)], 'r', 'LineWidth', 5);
axis equal
This will plot a half sphere at pt1, so I can get the translation to work fine. My problem comes with translating it properly so that I get the shape I wanted in the picture earlier. At first I thought about adding theta_rot, phi_rot to my phi and theta, but that didn't work.
Any ideas?
Brian on 12 Nov 2015
I wanted to try to stay in cylindrical coordinates, that's why I didn't use the sphere function.
I can use rotate after I get x,y,z, and that was what I was mainly asking about: I can do the translation easily, but I can't do my desired rotation easily.
I'm going to look at doing some cartesian rotations later today, because I'm not sure my spherical rotations make any sense the longer I look at them.
hgtransform looks potentially useful, but I'm not as interested in graphics as much as the domain itself, unfortunately.
Thanks, will continue to look at this.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!