How to draw a curve line with points between it on the shaded region that situated on the surface of the hemisphere using Matlab?2019 Community Moderator ElectionShading between vertical lines in MATLABhow to draw curved line in MatlabMatlab: Set shading of single surfaceDraw lines between points in MatlabMatlab - Shade the surface between 2 vertical curvesMatlab: Drawing Curve and Obtaining Points that are on the CurveShade a subset of a sphere's surface in MATLABMATLAB Shading region between SEVERAL curvesMatlab: Intersection point between 3D surface and curveHow to apply PSO algorithm on the surface of the shaded region of a hemisphere?
Too soon for a plot twist?
Vector-transposing function
Why restrict private health insurance?
PTIJ: Sport in the Torah
Draw this image in the TIKZ package
Can I negotiate a patent idea for a raise, under French law?
Are small insurances worth it?
I am the person who abides by rules but breaks the rules . Who am I
How can I portion out frozen cookie dough?
Short story about an infectious indestructible metal bar?
Is it appropriate to ask a former professor to order a library book for me through ILL?
How to install "rounded" brake pads
Should I apply for my boss's promotion?
What is Tony Stark injecting into himself in Iron Man 3?
Create chunks from an array
Boss Telling direct supervisor I snitched
Does the US political system, in principle, allow for a no-party system?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
Should we avoid writing fiction about historical events without extensive research?
Unfamiliar notation in Diabelli's "Duet in D" for piano
A vote on the Brexit backstop
Did Amazon pay $0 in taxes last year?
ESPP--any reason not to go all in?
How does a sound wave propagate?
How to draw a curve line with points between it on the shaded region that situated on the surface of the hemisphere using Matlab?
2019 Community Moderator ElectionShading between vertical lines in MATLABhow to draw curved line in MatlabMatlab: Set shading of single surfaceDraw lines between points in MatlabMatlab - Shade the surface between 2 vertical curvesMatlab: Drawing Curve and Obtaining Points that are on the CurveShade a subset of a sphere's surface in MATLABMATLAB Shading region between SEVERAL curvesMatlab: Intersection point between 3D surface and curveHow to apply PSO algorithm on the surface of the shaded region of a hemisphere?
A hemisphere with shaded region is already formed. Then, planning to form a path or curved line on the shaded region situated on the surface of the hemisphere with points on it. Can't even know what is their latitude or longitude to draw an arc, therefore, any idea on how to obtain the latitude and longitude for the starting and ending point or form a curved line as shown in the figure below?

[x,y,z] = sphere; % Makes a 21-by-21 point sphere
x = x(11:end,:); % Keep top 11 x points
y = y(11:end,:); % Keep top 11 y points
z = z(11:end,:); % Keep top 11 z points
radius = 0.13;
c = [0.36 0 0];
hs = surf(radius.*x + c(1),radius.*y,radius.*z,'FaceColor','yellow','FaceAlpha',.3);
axis equal
xlabel('X');ylabel('Y');zlabel('Z');
% Putting the ranges for the elevation and azimuth
minAzimuth = 0;
maxAzimuth = 180;
minElevation = 0;
maxElevation = 80;
% Compute angles
phi = atan2d(y,x);
theta = acosd (z);
% Highlighting logic (Shading the subset of the hemisphere)
ind = (phi >= minAzimuth & phi <= maxAzimuth) & (theta >= minElevation & theta <= maxElevation); % Find those indices
x2 = x; y2 = y; z2 = z; % Make a copy of the hemisphere coordinates
x2(~ind) = NaN; y2(~ind) = NaN; z2(~ind)=NaN; % Set those out of boundary to NaN
hold on;
surf(radius.*x2+c(1),radius.*y2,radius.*z2,'FaceColor','red');
matlab
add a comment |
A hemisphere with shaded region is already formed. Then, planning to form a path or curved line on the shaded region situated on the surface of the hemisphere with points on it. Can't even know what is their latitude or longitude to draw an arc, therefore, any idea on how to obtain the latitude and longitude for the starting and ending point or form a curved line as shown in the figure below?

[x,y,z] = sphere; % Makes a 21-by-21 point sphere
x = x(11:end,:); % Keep top 11 x points
y = y(11:end,:); % Keep top 11 y points
z = z(11:end,:); % Keep top 11 z points
radius = 0.13;
c = [0.36 0 0];
hs = surf(radius.*x + c(1),radius.*y,radius.*z,'FaceColor','yellow','FaceAlpha',.3);
axis equal
xlabel('X');ylabel('Y');zlabel('Z');
% Putting the ranges for the elevation and azimuth
minAzimuth = 0;
maxAzimuth = 180;
minElevation = 0;
maxElevation = 80;
% Compute angles
phi = atan2d(y,x);
theta = acosd (z);
% Highlighting logic (Shading the subset of the hemisphere)
ind = (phi >= minAzimuth & phi <= maxAzimuth) & (theta >= minElevation & theta <= maxElevation); % Find those indices
x2 = x; y2 = y; z2 = z; % Make a copy of the hemisphere coordinates
x2(~ind) = NaN; y2(~ind) = NaN; z2(~ind)=NaN; % Set those out of boundary to NaN
hold on;
surf(radius.*x2+c(1),radius.*y2,radius.*z2,'FaceColor','red');
matlab
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday
add a comment |
A hemisphere with shaded region is already formed. Then, planning to form a path or curved line on the shaded region situated on the surface of the hemisphere with points on it. Can't even know what is their latitude or longitude to draw an arc, therefore, any idea on how to obtain the latitude and longitude for the starting and ending point or form a curved line as shown in the figure below?

[x,y,z] = sphere; % Makes a 21-by-21 point sphere
x = x(11:end,:); % Keep top 11 x points
y = y(11:end,:); % Keep top 11 y points
z = z(11:end,:); % Keep top 11 z points
radius = 0.13;
c = [0.36 0 0];
hs = surf(radius.*x + c(1),radius.*y,radius.*z,'FaceColor','yellow','FaceAlpha',.3);
axis equal
xlabel('X');ylabel('Y');zlabel('Z');
% Putting the ranges for the elevation and azimuth
minAzimuth = 0;
maxAzimuth = 180;
minElevation = 0;
maxElevation = 80;
% Compute angles
phi = atan2d(y,x);
theta = acosd (z);
% Highlighting logic (Shading the subset of the hemisphere)
ind = (phi >= minAzimuth & phi <= maxAzimuth) & (theta >= minElevation & theta <= maxElevation); % Find those indices
x2 = x; y2 = y; z2 = z; % Make a copy of the hemisphere coordinates
x2(~ind) = NaN; y2(~ind) = NaN; z2(~ind)=NaN; % Set those out of boundary to NaN
hold on;
surf(radius.*x2+c(1),radius.*y2,radius.*z2,'FaceColor','red');
matlab
A hemisphere with shaded region is already formed. Then, planning to form a path or curved line on the shaded region situated on the surface of the hemisphere with points on it. Can't even know what is their latitude or longitude to draw an arc, therefore, any idea on how to obtain the latitude and longitude for the starting and ending point or form a curved line as shown in the figure below?

[x,y,z] = sphere; % Makes a 21-by-21 point sphere
x = x(11:end,:); % Keep top 11 x points
y = y(11:end,:); % Keep top 11 y points
z = z(11:end,:); % Keep top 11 z points
radius = 0.13;
c = [0.36 0 0];
hs = surf(radius.*x + c(1),radius.*y,radius.*z,'FaceColor','yellow','FaceAlpha',.3);
axis equal
xlabel('X');ylabel('Y');zlabel('Z');
% Putting the ranges for the elevation and azimuth
minAzimuth = 0;
maxAzimuth = 180;
minElevation = 0;
maxElevation = 80;
% Compute angles
phi = atan2d(y,x);
theta = acosd (z);
% Highlighting logic (Shading the subset of the hemisphere)
ind = (phi >= minAzimuth & phi <= maxAzimuth) & (theta >= minElevation & theta <= maxElevation); % Find those indices
x2 = x; y2 = y; z2 = z; % Make a copy of the hemisphere coordinates
x2(~ind) = NaN; y2(~ind) = NaN; z2(~ind)=NaN; % Set those out of boundary to NaN
hold on;
surf(radius.*x2+c(1),radius.*y2,radius.*z2,'FaceColor','red');
matlab
matlab
edited yesterday
Shuu
asked 2 days ago
ShuuShuu
32
32
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday
add a comment |
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday
add a comment |
1 Answer
1
active
oldest
votes
Use spherical coordinates:
As you did with your sphere segment, it is easier to define your line in spherical coordinates first, then convert to cartesian when it's time to display.
If you add this after your own code:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
You'll obtain a line parallel to the latitude you set:
You can adjust where the line starts, stops, and it elevation by adjusting the first parameters on top of the code (make them match your own values).
Edit:
To explain the spherical coordinate generation:
To get a line in 3D you need a set of 3 coordinates, they can be x/y/z (cartesian referential) or radius/azimuth/elevation (spherical referential).
The constraints for your line are:
Azimuth: (called
azp) Has to vary from one value to another. For that I used the statementazp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;. I recommend you to read the documentation for thelinspacefunction. It will generate a set ofnplinearly spaced points betweenLineAziStartandLineAziStop. I also had to usedeg2radbecause for sperical coordinates you want your angles expressed in radian.Radius: (called
rp) This one is easy. Your line has to be on the surface of the sphere, so all the points of the line will have the sameradiusvalue (the radius of the original sphere. We just generate a vector ofnppoints all equal to radius. This is done withrp = zeros(np,1) + radius;.Elevation: (called
elp) Your line has to be parallel to a latitude, so the elevation is also constant for all the points of the line. As with the radius, we generate the set of constant points the same way:elp = zeros(np,1) + deg2rad(LineElevation) ;.
By then you have a set of 3 vectors (rp/azp/elp), which all have the same number of values, and together define a set of point in 3D space, in spherical coordinates. Matlab plotting function requires cartesian coordinates so the last step is just to convert this set of coordinates. This is done with the function sph2cart, which convert rp/azp/elp into xp/yp/zp.
The spherical coordinates we generated were centered on the origin (point 0,0,0,), so the converted cartesian coordinates are also there. The last step is simply to translate these coordinates so they'll be centered on the same point/center than the sphere. After that, your coordinates are ready to be plotted.
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026446%2fhow-to-draw-a-curve-line-with-points-between-it-on-the-shaded-region-that-situat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use spherical coordinates:
As you did with your sphere segment, it is easier to define your line in spherical coordinates first, then convert to cartesian when it's time to display.
If you add this after your own code:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
You'll obtain a line parallel to the latitude you set:
You can adjust where the line starts, stops, and it elevation by adjusting the first parameters on top of the code (make them match your own values).
Edit:
To explain the spherical coordinate generation:
To get a line in 3D you need a set of 3 coordinates, they can be x/y/z (cartesian referential) or radius/azimuth/elevation (spherical referential).
The constraints for your line are:
Azimuth: (called
azp) Has to vary from one value to another. For that I used the statementazp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;. I recommend you to read the documentation for thelinspacefunction. It will generate a set ofnplinearly spaced points betweenLineAziStartandLineAziStop. I also had to usedeg2radbecause for sperical coordinates you want your angles expressed in radian.Radius: (called
rp) This one is easy. Your line has to be on the surface of the sphere, so all the points of the line will have the sameradiusvalue (the radius of the original sphere. We just generate a vector ofnppoints all equal to radius. This is done withrp = zeros(np,1) + radius;.Elevation: (called
elp) Your line has to be parallel to a latitude, so the elevation is also constant for all the points of the line. As with the radius, we generate the set of constant points the same way:elp = zeros(np,1) + deg2rad(LineElevation) ;.
By then you have a set of 3 vectors (rp/azp/elp), which all have the same number of values, and together define a set of point in 3D space, in spherical coordinates. Matlab plotting function requires cartesian coordinates so the last step is just to convert this set of coordinates. This is done with the function sph2cart, which convert rp/azp/elp into xp/yp/zp.
The spherical coordinates we generated were centered on the origin (point 0,0,0,), so the converted cartesian coordinates are also there. The last step is simply to translate these coordinates so they'll be centered on the same point/center than the sphere. After that, your coordinates are ready to be plotted.
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
add a comment |
Use spherical coordinates:
As you did with your sphere segment, it is easier to define your line in spherical coordinates first, then convert to cartesian when it's time to display.
If you add this after your own code:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
You'll obtain a line parallel to the latitude you set:
You can adjust where the line starts, stops, and it elevation by adjusting the first parameters on top of the code (make them match your own values).
Edit:
To explain the spherical coordinate generation:
To get a line in 3D you need a set of 3 coordinates, they can be x/y/z (cartesian referential) or radius/azimuth/elevation (spherical referential).
The constraints for your line are:
Azimuth: (called
azp) Has to vary from one value to another. For that I used the statementazp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;. I recommend you to read the documentation for thelinspacefunction. It will generate a set ofnplinearly spaced points betweenLineAziStartandLineAziStop. I also had to usedeg2radbecause for sperical coordinates you want your angles expressed in radian.Radius: (called
rp) This one is easy. Your line has to be on the surface of the sphere, so all the points of the line will have the sameradiusvalue (the radius of the original sphere. We just generate a vector ofnppoints all equal to radius. This is done withrp = zeros(np,1) + radius;.Elevation: (called
elp) Your line has to be parallel to a latitude, so the elevation is also constant for all the points of the line. As with the radius, we generate the set of constant points the same way:elp = zeros(np,1) + deg2rad(LineElevation) ;.
By then you have a set of 3 vectors (rp/azp/elp), which all have the same number of values, and together define a set of point in 3D space, in spherical coordinates. Matlab plotting function requires cartesian coordinates so the last step is just to convert this set of coordinates. This is done with the function sph2cart, which convert rp/azp/elp into xp/yp/zp.
The spherical coordinates we generated were centered on the origin (point 0,0,0,), so the converted cartesian coordinates are also there. The last step is simply to translate these coordinates so they'll be centered on the same point/center than the sphere. After that, your coordinates are ready to be plotted.
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
add a comment |
Use spherical coordinates:
As you did with your sphere segment, it is easier to define your line in spherical coordinates first, then convert to cartesian when it's time to display.
If you add this after your own code:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
You'll obtain a line parallel to the latitude you set:
You can adjust where the line starts, stops, and it elevation by adjusting the first parameters on top of the code (make them match your own values).
Edit:
To explain the spherical coordinate generation:
To get a line in 3D you need a set of 3 coordinates, they can be x/y/z (cartesian referential) or radius/azimuth/elevation (spherical referential).
The constraints for your line are:
Azimuth: (called
azp) Has to vary from one value to another. For that I used the statementazp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;. I recommend you to read the documentation for thelinspacefunction. It will generate a set ofnplinearly spaced points betweenLineAziStartandLineAziStop. I also had to usedeg2radbecause for sperical coordinates you want your angles expressed in radian.Radius: (called
rp) This one is easy. Your line has to be on the surface of the sphere, so all the points of the line will have the sameradiusvalue (the radius of the original sphere. We just generate a vector ofnppoints all equal to radius. This is done withrp = zeros(np,1) + radius;.Elevation: (called
elp) Your line has to be parallel to a latitude, so the elevation is also constant for all the points of the line. As with the radius, we generate the set of constant points the same way:elp = zeros(np,1) + deg2rad(LineElevation) ;.
By then you have a set of 3 vectors (rp/azp/elp), which all have the same number of values, and together define a set of point in 3D space, in spherical coordinates. Matlab plotting function requires cartesian coordinates so the last step is just to convert this set of coordinates. This is done with the function sph2cart, which convert rp/azp/elp into xp/yp/zp.
The spherical coordinates we generated were centered on the origin (point 0,0,0,), so the converted cartesian coordinates are also there. The last step is simply to translate these coordinates so they'll be centered on the same point/center than the sphere. After that, your coordinates are ready to be plotted.
Use spherical coordinates:
As you did with your sphere segment, it is easier to define your line in spherical coordinates first, then convert to cartesian when it's time to display.
If you add this after your own code:
% set line parameters
np = 10 ; % number of points
LineAziStart = 17 ; % Starting azimuth
LineAziStop = 122 ; % Ending azimuth
LineElevation = 49 ; % Elevation
% generate spherical coordinates
azp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;
elp = zeros(np,1) + deg2rad(LineElevation) ;
rp = zeros(np,1) + radius ;
% convert to cartesian
[xp,yp,zp]=sph2cart(azp,elp,rp) ;
% adjust coordinates for center of the sphere
xp = xp + c(1) ;
yp = yp + c(2) ;
zp = zp + c(3) ;
% display
hp = plot3(xp,yp,zp,'g','LineWidth',2,'Marker','x') ;
You'll obtain a line parallel to the latitude you set:
You can adjust where the line starts, stops, and it elevation by adjusting the first parameters on top of the code (make them match your own values).
Edit:
To explain the spherical coordinate generation:
To get a line in 3D you need a set of 3 coordinates, they can be x/y/z (cartesian referential) or radius/azimuth/elevation (spherical referential).
The constraints for your line are:
Azimuth: (called
azp) Has to vary from one value to another. For that I used the statementazp = linspace(deg2rad(LineAziStart),deg2rad(LineAziStop),np).' ;. I recommend you to read the documentation for thelinspacefunction. It will generate a set ofnplinearly spaced points betweenLineAziStartandLineAziStop. I also had to usedeg2radbecause for sperical coordinates you want your angles expressed in radian.Radius: (called
rp) This one is easy. Your line has to be on the surface of the sphere, so all the points of the line will have the sameradiusvalue (the radius of the original sphere. We just generate a vector ofnppoints all equal to radius. This is done withrp = zeros(np,1) + radius;.Elevation: (called
elp) Your line has to be parallel to a latitude, so the elevation is also constant for all the points of the line. As with the radius, we generate the set of constant points the same way:elp = zeros(np,1) + deg2rad(LineElevation) ;.
By then you have a set of 3 vectors (rp/azp/elp), which all have the same number of values, and together define a set of point in 3D space, in spherical coordinates. Matlab plotting function requires cartesian coordinates so the last step is just to convert this set of coordinates. This is done with the function sph2cart, which convert rp/azp/elp into xp/yp/zp.
The spherical coordinates we generated were centered on the origin (point 0,0,0,), so the converted cartesian coordinates are also there. The last step is simply to translate these coordinates so they'll be centered on the same point/center than the sphere. After that, your coordinates are ready to be plotted.
edited 14 hours ago
answered yesterday
HokiHoki
9,12911336
9,12911336
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
add a comment |
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
Cool. But may I know about the generate spherical coordinates part? I'm not quite understand with the elp and rp. Thanks.
– Shuu
16 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
@Shuu, explanations added in the answer.
– Hoki
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
I got it now. Thanks for the explanation :)
– Shuu
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
@Shuu you're welcome. Consider accepting the answer if it sorted your problem.
– Hoki
14 hours ago
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026446%2fhow-to-draw-a-curve-line-with-points-between-it-on-the-shaded-region-that-situat%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I don't understand what you are asking for. Your drawing suggests that the path lies along a parallel of latitude, it's easy to generate a list of points at intervals along such a path. Slightly more difficult, but extensively studied and copiously and well documented in 1,000 places on the 'net, is the construction of a great circle segment from start to finish.
– High Performance Mark
2 days ago
Sorry about that. But yes, need to create the path lies along a parallel of latitude, but need to create the path or great circle segment from start to finish first right? Yet, I cant seem to create the path on the shaded region like the one I shown in the figure.
– Shuu
yesterday