Help with declaring half sphere with point, direction vector
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
[theta,phi]=meshgrid(theta,phi);
x=r*sin(phi).*cos(theta) + pt1(1);
y=r*sin(phi).*sin(theta) + pt1(2);
z=r*cos(phi) + pt1(3);
mesh(x,y,z);
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?
2 commentaires
Star Strider
le 12 Nov 2015
If you’re not already aware of them, two core MATLAB functions that could help you are sphere and rotate. The hgtransform function and its friends could also be helpful.
Réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!