find the line equation of two points in 3D
2 ビュー (過去 30 日間)
古いコメントを表示
hi.
I have a problem, here is my code
cama=[-412.3, 24.6, 630.9];
camb=[483.4, 35.8, 605.5];
dz=-36;
loca=[-0.3, 24.8, 0];
locb=[44.5, 23.9, 0];
figure; hold on; grid on;view(0,0)
plot3(cama(1), cama(2), cama(3), 'r*');
plot3(camb(1), camb(2), camb(3), 'b*');
plot3(loca(1), loca(2), loca(3), 'ro');
plot3(locb(1), locb(2), locb(3), 'bo');
plot3([cama(1), loca(1)], [cama(3), loca(3)], [cama(3), loca(3)], 'k')
plot3([camb(1), locb(1)], [camb(3), locb(3)], [camb(3), locb(3)], 'k')
i need to find the point of the intersecting lines or a close point, one that is on z=-36, how can I do that?
thanks
0 件のコメント
回答 (2 件)
Babak
2012 年 10 月 15 日
To find the intersection of two lines (curves) for which you have numerical data, like f(n) and g(n) you can first compute h(n) = abs(f(n)-g(n)) then find the minimum of h(n), find the index j at which h(n) has a local minimum and check that either (f(j)-g(j))*(f(j+1)-g(j+1))<0 or (f(j)-g(j))*(f(j-1)-g(j-1))<0.
If none of the two is correct then the local minimum you've found does not correspond to an intersection point but if (f(j)-g(j))*(f(j+1)-g(j+1))<0 the intersection is happenning from j to j+1 index and if (f(j)-g(j))*(f(j-1)-g(j-1))<0 then the intersection is happennig from j-1 to j index. either way to find the more precise location of the intersection you can interpolate between the data of f(j)-g(j) and f(j+1)-g(j+1) for example. Or obviously interpolate between the data of f(j)-g(j) and f(j+1)-g(j+1).
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!