-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetErrTransformationParas.m
64 lines (55 loc) · 2.09 KB
/
getErrTransformationParas.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [R, errD] = getErrTransformationParas(dqRefFeature, dqMovingFeature, Ps, ULPS, xyzDir)
% gets tranfomation operators Rotation R and Translation ERRD for inputs
% input reference and moving feature dual quaternions, locator points PS,
% the direction of the displacement towards tertiary ULPS and assembly
% direction XYZDIR
include_namespace_dq
dqRefFeature = DQ(dqRefFeature);
dqMovingFeature = DQ(dqMovingFeature);
normalRef = dqRefFeature.P.vec3;
normalFeature = dqMovingFeature.P.vec3;
global aOfRotation
switch xyzDir
case 2
axisOfRotation = aOfRotation;
case 1
% No rotation in this axis
R = zeros(8, 1); R(1) = 1;
newTerPlane = DQ(normalize(ULPS)) + E_ * norm(Ps(6, :)*ULPS);
errD = newTerPlane - dqMovingFeature;
dqRefFeature = newTerPlane;
normalRef = dqRefFeature.P.vec3;
case 3
axisOfRotation = getMyNormal([0, 0, 0], normalRef', normalFeature');
aOfRotation = normalRef;
end
% Rotation is needed only in direction of x-1 and z-3
if xyzDir == 2 || xyzDir == 3
alpha = rad2deg(anglePoints3d(normalRef', normalFeature'));
if xyzDir == 2
% project vectors to horizontal plane
normalRef(3) = 0;
normalFeature(3) = 0;
alpha = rad2deg(anglePoints3d(normalRef', normalFeature'));
end
if alpha > 90
alpha = 180 - alpha;
end
%%
R = rot2dquat(alpha, axisOfRotation');
movedFeature = moveFeaturesBy(dqMovingFeature.vec8, R);
refDir = normalize(dqRefFeature.P.vec3);
movedDir = normalize(DQ(movedFeature).P.vec3);
f = find(abs(refDir) == max(abs(refDir)));
r = refDir(f) / movedDir(f);
tol = 10e-8;
if abs(movedDir(1)*r-refDir(1)*r) > tol & abs(movedDir(2)*r-refDir(2)*r) > tol
R = rot2dquat(-alpha, axisOfRotation');
movedFeature = DQmult(R, dqMovingFeature.vec8, DQconj(R));
end
dqRefFeature = dqRefFeature.vec8;
errTT = getProjectedTestPointsPlucker2(dqRefFeature, [0, 0, 0], normalRef) - ...
getProjectedTestPointsPlucker2(movedFeature, [0, 0, 0], normalRef);
errD = errTT * normalRef;
end
end