3D Ray Intersecting a 3D Sphere
3 views (last 30 days)
Show older comments
Hi,
I am a little stumped, I am trying to create a 3D sphere and have a 3D ray to pass through it.
I currently have 3 pieces of code, the first being the 3D sphere code shown below:
clc
%clear the screen%
clear
%Create a 3 by 1 Matrix with x, y and z co-ordinates equaling the sphere
[x y z] = sphere;
%creating a new variable called a with a 4 by 1 array showing its x, y, z
%position and its radius%
a=[3 3 3 3]
s1=surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3));
%setting the axis data of the viewport to 1, 1, 1%
daspect([1 1 1])
%Setting the viewers orientation of the axis%
view(30,10)
end
The second code is the 3D ray:
function [ output_args ] = Raycast( input_args )
%RAYCAST Summary of this function goes here
% Detailed explanation goes here
% two points
P1 = [0,0,0];
P2 = [13,-11,19];
% vertial concatenation
pts = [P1; P2];
% use plot3:
plot3(pts(:,1), pts(:,2), pts(:,3))
end
I am trying to get them both in the same document but when I try it will either only show the sphere or show nothing it doesn't seem to work together, what am I doing wrong?, the whole code is below:
function [ output_args ] = Sphere( input_args )
%SPHERE Summary of this function goes here
% Detailed explanation goes here
clc
%clear the screen%
clear
%Create a 3 by 1 Matrix with x, y and z co-ordinates equaling the sphere
[x y z] = sphere;
%creating a new variable called a with a 4 by 1 array showing its x, y, z
%position and its radius%
a=[3 3 3 3]
s1=surf(x*a(1,4)+a(1,1),y*a(1,4)+a(1,2),z*a(1,4)+a(1,3));
%setting the axis data of the viewport to 1, 1, 1%
daspect([1 1 1])
%Setting the viewers orientation of the axis%
view(30,10)
% two points
P1 = [0,0,0];
P2 = [13,-11,19];
% vertial concatenation
pts = [P1; P2];
% use plot3:
plot3(pts(:,1), pts(:,2), pts(:,3))
end
0 Comments
Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!