get 3D angles of vectors

조회 수: 3 (최근 30일)
Carlos Fambuena
Carlos Fambuena 2019년 10월 8일
댓글: darova 2019년 10월 8일
Hi,
I am trying to calculate the angles and link lengths to fit some manipulators to a 3D curve. I have done this so far, but apparently the calculation of the ngles is not accurate enough and I have a considerable position error when I reconstruct the manipulators using the angles and link lengths obtained from this function. Any idea of what could be going wrong or how to improve this? Thanks you beforehand.
function [ang,ind1,L] = fitManipulators(cit,pc,ns,rL)
%This function fits manipulators of three double joints each to a curve. That is,
%calculates the length of the links and the angles of the joints so the
%manipulators follow the curve.
%INPUTS:
%cit: Matrix of 3D points N by 3 in the curve.
%pc: Vector with the indexes where the segment start and end.
%ns: Number of segments in which the curve is going to be splited. This
% number concides also with the number of manipulators.
%rL: relative length of those segments w.r.t the total length of the 3D
% the segment they belong to.
%OUTPUTS:
%ang: Angles of the joints of the manipulators
%ind1: Indexes of the curve where there is a joint
%L: ns by 3 matrix with the lengths of the links of each manipulator.
ang = zeros(ns*6,1);
angz_1 = 0;
angx_1 = 0;
ind1 = zeros(1,ns*3);
L = zeros(ns,3);
f = 1;
for i =1:ns
Ls = pc(i+1)-pc(i); %Length of the segment
ind = pc(i); %Index
k = 1;
for j =1:2:6
ind1(f) = ind+round(Ls*rL(k)); %Getting the next index
vj = cit(ind,:); %Getting the 3D coordinates
vj1 = cit(ind1(f),:);
vd = vj1 - vj;
L(i,k) = norm(vd);
angx = atan2(vd(3),norm([vd(1) vd(2)]));
angz = atan2(vd(1),norm([vd(2) vd(3)]));
angz = angz-angz_1;
angx = angx-angx_1;
ang(6*(i-1)+j:6*(i-1)+j+1) = [angz;angx];
angz_1 = angz;
angx_1 = angx;
ind = ind1(f);
k = k+1;
f =f+1;
end
end
end
  댓글 수: 3
darova
darova 2019년 10월 8일
Can you make a simple drawing where you show what angles do you need?
121Untitled.png
Carlos Fambuena
Carlos Fambuena 2019년 10월 8일
Hi Dorva, the angles that I want to calculate are those in figure 1.
angles.png

댓글을 달려면 로그인하십시오.

채택된 답변

darova
darova 2019년 10월 8일
If cit is your 3D data
vj = cit(ind,:); %Getting the 3D coordinates
use cart2sph
v = diff(cit); % vectors in 3D
[az,el,~] = cart2sph(v(:,1),v(:,2),v(:,3));
% angles between vectors
az_diff = diff(az);
el_diff = diff(el);
11Capture.PNG
  댓글 수: 2
Carlos Fambuena
Carlos Fambuena 2019년 10월 8일
Thank you very much! This function works very well.
darova
darova 2019년 10월 8일
You can accept the answer so i will be paid

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by