How can i create xyz coordinant from pan-tilt system angles.

Hello guys, I have 3 data, First servo angle for pan, second servo angle for tilt and measurement from the laser. If I can able to get xyz points, so I can use it as meshing point to 3D mapping by using software such as CloudCompare or MeshLab.

2 Comments

Hard to understand what you want. Try drawing a picture to illustrate the problem.
Dear Jim, https://www.youtube.com/watch?v=kJW9Uy4j-6k My project is as same as the project in this video.
I have 2 angle from servos and 1 data from laser meter. For mapping i need to get xyz coordinant from the datas
I hope you understand me now.

Sign in to comment.

 Accepted Answer

It seems that you want to convert from spherical coordinates to Cartesian coordinates. You have pan angle (azimuth) and a tile angle (elevation), and the "1 data from laser meters" I assume that this is the range (or radius) in meters.
Matlab has a function which will perform this conversion called sph2cart:
[x,y,z] = sph2cart(azimuth,elevation,radius);
This function performs the following transformation:
x = radius .* cos(elevation) .* cos(azimuth);
y = radius .* cos(elevation) .* sin(azimuth);
z = radius .* sin(elevation);

5 Comments

Dear Jim, Thanks for the feedback. I already have used that function. There is something that I never understand. Here is my code.
clc
clear
servo1= [1:180]; %from 1° to 180° for pan
servo2= zeros(1,180);
servo2= servo2+30; % constant 30° for tilt
length= zeros(1,180);
length=length + 500; % constant measurement from laser sensor which is 500mm
[x,y,z] = sph2cart(servo1,servo2,length);
plot3(x,y,z);
end
As a result, it should be a circle as expected since the measurement is constant. There is no problem.
But when i wanted to get the rectangular shape. Think of it as I am scanning a room. Here is the code about it.
clc
clear
servo1= [1:180]; %from 1° to 180° for pan
servo2= zeros(1,180);
servo2= servo2+30; % constant 30° for tilt
a=zeros(1,45);
a=a+200;
b=zeros(1,90);
b=b+500;
length=[a,b,a]; % first 45 datas is 200mm, then 500mm, last datas are also 200mm
[x,y,z] = sph2cart(servo1,servo2,length);
plot3(x,y,z);
end
When I plot to xyz points, it shows me an unexpected result.
I expecting that it should be rectangular. Why i get this shape as a result?
First of all, you are using units of degrees for your angles, but the Matlab function sph2cart is using radians. So your plot is made up of 180 points in azimuth that are spaced 1 radian (57.3 degrees) apart, and with a constat elevation angle of +30 radians, which is equivalent to -81.1 degrees. (This is why your Z values are negative)
The plot is made from 3 groups of points: 1) you have 45 points with a radius of a constant 200, at a constant elevation of -81.1 degrees, and spaced by 57.3 degrees in azimuth. This creates the small circle at Z = 200 x sin(-81.1 degrees) = -197.5.
2) Then you have 90 points at a constant radius of 500, at constant elevation of -81.1 degrees, which are spaced in azimuth at 57.3 degree intervals, this creates the larger circle at Z = 500 x sin(-81.1 degrees) = -494.
3) then you have another group of 45 points, identical to the first group. (This is why the small circle is connected to the large circle by the two lines.)
Since the radius values are constant for each group, you get circles.
Thank you Jim. I totally understand. So, how can I analyze my data to create xyz point? Do you have any recommendation?
I am not sure what you are asking. If you have pan/tilt/range measurements, you can convert them directly to X/Y/Z coordinates. Just make sure that your pan/tilt angles are in radians when you call the sph2cart function. Or, you can write your own function using the three equations, above, and use the sind and cosd functions to operate in your data in degrees.
function [x, y, z] = my_sph2cart(pan,tilt,range)
x = range .* cosd(tilt) .* cosd(pan);
y = range .* cosd(tilt) .* sind(pan);
z = range .* sind(tilt);
end

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

Aui
on 2 Nov 2018

Commented:

Aui
on 8 Nov 2018

Community Treasure Hunt

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

Start Hunting!