This is my problem (each landmark is a marker) :
I need to express R1->R2. Aruco gives me transform between R1->RR and R2->RR.
R1 = T1.RR (with T1 = transfo matrix containing rvec and tvec)
R2 = T2.RR <=> RR = inv(T2).R2
<=> R1 = T1.inv(T2).R2
The problem is that for me, I should have R1 = inv(T2).T1.R2 but I don't know where I'm wrong ...
Thanks,
Alan
Related
I am working on a drawing application. I summerize the main question to a tiny scenario:
User draws the line A1-B1 and also the point M1. Now user moves the line A1-B1 to a new position A2-B2 while the point M1 also should move with the line (like a rigid body). How can I calculate the new position of point M2?
I know it is possbile with complex calucations on lines or circles conjuction and finally detemrining if the new point is on the right or left of line (this question) etc. But as I want to recalculate live on any steps of dragging, I guess there should be a shortcut and light solution which all modeling softwares use. Is there really a shortcut formula rahter than the line or circle conjuctions?
To summerize the problem again I am looking for a light function with given A1,B1,A2,B2,M1 and looking for M2 position (two separate formula for x and y)
M2 = f(A1,B1,A2,B2,M1)
My guess: I think finding the center and the angle of rotation is one of the best options but I don't know again if there is a shotcut function to find them.
Edit: I prefer to implement it in an online website, so if there is a ready javascript library, it would be helpful, However I am now just looking for the mathematical logic.
Start with A1 and B1.
D = B1 - A1
C1 = D/|D|
Rotate C1 90 degrees counter-clockwise to get C'1:
C1 = (cx, cy)
C'1 = (-cy, cx)
Now take M1 - A1 and measure it against C1 and C'1:
j = (M1 - A) · C1
k = (M1 - A) · C'1
Now it's easy to prove:
M1 = A1 + j C1 + k C'1
So j and k tell you where M1 is, given A1 and B1.
When you get A2 and B2, use them to construct C2, rotate it to get C'2, and then you'll have:
M2 = A2 + j C2 + k C'2
I'm assuming points are objects which have x and y values. Like this:
A1 = {x: 100, y:100}
Here's a lightweight solution:
function reposition(A1,A2,B1,B2,M1)
{
//Getting the Angle Between Lines
var angle = Math.atan2(B2.y-B1.y, B2.x-B1.x)-Math.atan2(A2.y-A1.y, A2.x-A1.x);
//Rotating the point
var xdif = M1.x-A1.x; //point.x-origin.x
var ydif = M1.y-A1.y; //point.y-origin.y
//Returning M2
return {x:B1.x + Math.cos(angle) * xdif - Math.sin(angle) * ydif, y: B1.y + Math.sin(angle) * xdif + Math.cos(angle) * ydif}
}
I am an R and IDL beginner. Im trying to convert an R script to IDL.
R can do array manipulation with t1 (array[100000]) but IDL cannot.
ERROR: Array subscript for CZ must have same size as source expression
s1= 100000.
c1 = array[200000]
n1 = s1*2+2
t1 = array[100000]
————————————————————————————————
(function)
f03, c1, s1, n1
cz = fltarr(n1,3)
cz[0:((2*s1)-1),0] = c1
cz[1:(2*s1),1] = c1
cz[2:((2*1)+1),2] = c1
cr = cz[0:(n1-1),1] - cz[0:(n1-1),2]
cl = cz[0:(n1-1),1] - cz[0:(n1-1),0]
p1 = where(cr GE 0.0 AND cl GE 0.0 AND (cz[0:(n1-1),1]) GE 1.4)
n2 = n_elements(p1)
ct = fltarr(n2+1,2)
ct[0:n2-1,0] = p1
ct[1:n2,1] = p1
c2 = ct[*,0] - ct[*,1]
ip = where(c2 GT 2.)
ch = p1[ip]
return, ch
————————————————————————————————
p1 = f03(c1,s1,n1) ;;;;; function works here
f1 = f03(t1,s1,n1) ;;;;; error on array size
I used MATRIX and AS.MATRIX in R (for f03). Does FLTARR cause this error?
Your lines:
cz = fltarr(n1, 3)
cz[0:((2 * s1) - 1), 0] = c1
make sense when cz has a first dimension of size 2000002 and c1 is 200000 elements — the sizes on the left and right of the = sign match, i.e., 0:199999 is 2000000 elements just like the size of c1.
But in the second call, c1 only has 100000 elements, but the left side is still asking for 2000000 elements.
Also, define a function like:
function f03, c1, s1, n1
; a bunch of code goes here
return, ch
end
I'm working on a project that calculates the derivative of the speed and the integral of the acceleration.
my problem is that I have a lot of acceleration points and speed over time and I can not find the right program for that.
example:
acceleration from 0 km / h to 40 km / h in 5 seconds
from 5 to 10 seconds, the speed is constant 40km/h;
from 10 to 17 seconds there is a deceleration from 40 km / h to 20 km / h
So dv/dt = (v2-v1)/(t2-t1) but I don't know how to declare multiple variables for v1 v2 t1 t2
function a=acc(v1,v2,t1,t2)
a= (v2-v1)/(t2-t1)
endfunction
v1=
v2=
t1=
t2=
disp(acc(v1,v2,t1,t2),'acc = ')
and the same for the integral of (dv/dt)*dt
please help me guys
V(1:5) = linspace(0,40,5);
V(6:10) = 40;
V(11:17) = linspace(40,20,7);
Acc = diff(V);
First we populate a array V with your values for the speed.
Then we create an array Acc with the acceleration a each seconds with diffsince there's only 1s between two values of V.
Another solution based on what you wrote
function a=acc_2(v1,v2,t1,t2)
a= (v2-v1)./(t2-t1) // since v,t are vectors, we need './' and not '/' !
endfunction
V(1:5) = linspace(0,40,5);
V(6:10) = 40;
V(11:17) = linspace(40,20,7);
v1 = V(1:$-1);
v2 = V(2:$);
t1 = 1:length(V)-1;
t2 = 2:length(V);
Acc_2 = acc_2(v1,v2,t1,t2)
And if you want to have h(x) = int_t0^x dv/dt dt then use cumsum
H = cumsum(Acc)
i put this code
V(1:5) = linspace(0,40,5);
V(6:10) = 40;
V(11:17) = linspace(40,20,7);
function a = acc(V)
a=diff(V)
endfunction
function aa = acc_2(v1,v2,t1,t2)
aa = (v2-v1)/(t2-t1)
endfunction
v1 = V(1:$-1);
v2 = V(2:$);
t1 = 1:length(V)-1;
t2 = 2:length(V);
Acc_2 = acc_2(v1,v2,t1,t2)
but he gives me the result of a single variable of Acc_2 ?
I'm trying to compute the Perceptually Important Points by using three different methods.
Euclidean Distance;
Perpendicular Distance;
Vertical Distance.
Method 2 and 3 gives me the same Point, but Euclidean distance not. Can't find the mistake I made. Hope someone can help me.
pt = 7.6 #pt
_t = 1 #t
ptT = 10.7 #p(t+T)
_T = 253 #t+T
# Distances
dE = Float64[] #Euclidean Distances
dP = Float64[] #Perpendicular Distances
dV = Float64[] #Vertical Distances
xi = Float64[] #x values
for i in 2:length(stockdf[:Price])-1
_de = sqrt((_t - i)^2 + (pt - stockdf[:Price][i])^2) + sqrt((_T - i)^2 + (ptT - stockdf[:Price][i])^2)
push!(dE,_de)
_dP = abs(_s*i+_c-stockdf[:Price][i])/sqrt(_s^2+1)
push!(dP,_dP)
_dV = abs(_s*i+_c-stockdf[:Price][i])
push!(dV,_dV)
push!(xi,i)
end
Both method 2 and 3 give me the max point indexed at 153, but method 1 gives me a point, which is not the max point and is indexed at 230.
Formula for the 3rd PIP with Euclidean Distance is:
dE = sqrt((t-i)^2 + (pt-pi)^2) + sqrt((t+T-i)^2+(pt+T-pi)^2)
EDIT:
For a better understanding I reproduced the code with other variables which you can test for yourself.
xs = Array(1:10)
ys = rand(1:1:10,10)
dde = Float64[]
ddP = Float64[]
ddV = Float64[]
xxi = Float64[]
# Connecting Line of first 2 PIPs
_ss = (ys[end]-ys[1])/10
_cc = ys[1]-(1*(ys[end]-ys[1]))/10
_zz = Float64[]
for i in 1:length(dedf[:Price])
push!(_zz,_ss*i+_cc)
end
for i in 2:length(xs)-1
_dde = sqrt((1-i)^2+(ys[1]-ys[i])) + sqrt((10-i)^2 + (ys[end]- ys[i])^2)
push!(dde,_dde)
_ddP = abs(_ss*i+_cc-ys[i])/sqrt(_ss^2+1)
push!(ddP,_ddP)
_ddV = abs(_ss*i+_cc-ys[i])
push!(ddV,_ddV)
push!(xxi,i)
end
println(dde)
for i in 1:length(dde)
if ddV[i] == maximum(ddV)
println(i)
end
end
For Euclidean Distance I get index 7
for Perpendicular and Vertical Distance I get index 5. Look at the graphs
Euclidean Distance on graph
Perpendicular Distance on graph
EDIT:
I'm working through a book about pattern recognition in financial time series. Now I downloaded the same data, which the book used and the now the results are the same. All of the 3 methods gave me the same index. But with different data sets, method 1 differs from 2 and 3. I don't know why.
I'm Trying to implement 3-plane intersection using the formula at the bottom of this wolfram page here: http://mathworld.wolfram.com/Plane-PlaneIntersection.html
If the three planes are each specified by a point xk and a unit normal vector
nk, then the unique point of intersection x is given by
x = (|n1 n2 n3|)^(-1) [(x1 · n1)(n2 x n3)+(x2 · n2)(n3 x n1)+(x3 · n3)(n3 x n2)],
where |n1 n2 n3| is the determinant of the matrix formed by writing the
vectors ni side-by-side. If two of the planes are parallel, then
|n1 n2 n3| = 0,
But this is as far as I can get, my matrix math is awful and I'm not that good with three.js matrices
var x1, x2, x3; // all clones
var n1, n2, n3; // all clones, normalized
var f1 = (x1.dot(n1)).something(n2.cross(n3));
var f2 = (x2.dot(n2)).something(n3.cross(n1));
var f3 = (x3.dot(n3)).something(n1.cross(n2));
var full = f1.add(f2).add(f3);
First off, what is '(x1 · n1)(n2 x n3)' supposed to mean? I know the first one is dot product and the section is cross product, what do I do to combine them
Second, how do I write the matrix portion in three.js
Here's a ready to use function (assembled from the answer from robertl below):
arguments: Planes p1,p2,p3
return: Vector3
function vertIntersectPlanes(p1, p2, p3)
{
let n1 = p1.normal, n2 = p2.normal, n3 = p3.normal;
let x1 = p1.coplanarPoint(new THREE.Vector3());
let x2 = p2.coplanarPoint(new THREE.Vector3());
let x3 = p3.coplanarPoint(new THREE.Vector3());
let f1 = new THREE.Vector3().crossVectors(n2, n3).multiplyScalar(x1.dot(n1));
let f2 = new THREE.Vector3().crossVectors(n3, n1).multiplyScalar(x2.dot(n2));
let f3 = new THREE.Vector3().crossVectors(n1, n2).multiplyScalar(x3.dot(n3));
let det = new THREE.Matrix3().set(n1.x, n1.y, n1.z, n2.x, n2.y, n2.z, n3.x, n3.y, n3.z).determinant();
let vectorSum = new THREE.Vector3().add(f1).add(f2).add(f3);
let planeIntersection = new THREE.Vector3(vectorSum.x / det, vectorSum.y / det, vectorSum.z / det);
return planeIntersection;
}
First:
What does (x1 · n1)(n2 x n3) mean?
The dot product (x1 · n1) produces a scalar value, namely the component of x1 parallel to n1.
The cross product (n2 x n3) produces a vector perpendicular to both n2 and n3.
Thus, the expression (x1 · n1)(n2 x n3) is the vector (n2 x n3), scaled/stretched/elongated by the scalar (x1 · n1).
Therefore, in three.js, to compute your variable f1,
var cross23 = new THREE.Vector3();
cross23.crossVectors(n2, n3); // stores the cross product (n2 x n3) in cross23
var scalar = x1.dot(n1);
var f1 = cross23;
f1.multiplyScalar(scalar);
Second:
To compute the determinant |n1 n2 n3|, first create the matrix, which we'll call M.
var M = THREE.Matrix3();
Now, we'll set the components of M as the documentation prescribes (http://threejs.org/docs/#Reference/Math/Matrix3).
M.set(n1.x, n1.y, n1.z, n2.x, n2.y, n2.z, n3.x, n3.y, n3.z);
Finally, we'll compute the determinant of the matrix.
var det = M.determinant();
Third:
Above, we've shown how to calculate det, f1, f2, and f3. Now, to compute the intersection of the planes, we must now calculate the expression det^-1 * (f1 + f2 + f3). We first compute the vector sum, f1 + f2 + f3, as follows.
var vectorSum = new THREE.Vector3(0, 0, 0);
vectorSum.add(f1);
vectorSum.add(f2);
vectorSum.add(f3);
Now, with both the determinant and the vector sum, we can compute the final answer, specifically the intersection of the planes.
var planeIntersection = new THREE.Vector3(vectorSum.x/det, vectorSum.y/det, vectorSum.z/det);