Having problems with 'all' command

3 次查看(过去 30 天)
Hi, I'm trying to find the parallel lines who meets at a certain point in 3D space. This is because my input data set lines from points (x,y,z) and some times they are parallel and i'm using this to my criteria.
I think that i've achieved my purpose by:
- getting the point of concurrence of lines
- getting the opposite point of each line
%if the crossed point is (xn,yn,zn) all lines have that point and i found the other one (xi,yi,zi)
- (xi,yi,zi)-(xn,yn,zn) returns the direction 'from crossed point to opposite point' of each line %used this way because the combinations in which my input data is organized
-then took the direction vector to unitary form.
%By doing this i know that parallel lines in the point will have opposite direction and therefor (a,b,c)=-(-a,-b,-c)
sayed the above, my code problem is the following:
paralela=find(all(repmat(auxnodoop3(j,1:3),nbarrasn,1)==-auxnodoop3,2))
%auxnodoop3 - is the unitary direction vector of each line at the crossed point.
%nbarrasn - is the number of lines reaching the point.
The expression in "paralelas" works fine when the line is also parallel to global X,Y,Z. but fails to identify equals component's vector when they are "free" in the space.
for example, at some point and j=3:
repmat() returns
0.5000 0.8660 0
0.5000 0.8660 0
0.5000 0.8660 0
(-auxnodoop3) returns
0.5000 0.8660 0
-0.8660 -0.5000 0
-0.5000 -0.8660 0
all() returns
0 0 1
0 0 1
0 0 1
but should be
1 1 1
0 0 1
0 0 1
The latters will means that line 3 and 1 are parallel
and if lines relies parallel to one of globals X,Y,Z the code works as follows (j=2):
0 0 -1
0 0 -1
0 0 -1
0 0 -1
0.5000 -0.8660 0
0 0 1.0000
-1.0000 0 0
0 0 -1.0000
0 0 0
1 1 0
0 1 0
1 1 1
Meaning that at some point the second and fourth lines are parallel
---------------------------------
I don't know why this is happening, just state the global axes parallelism because in that cases the code works. But shouldn't by related. Also I tried by changing digits() if there were some possibility... but not. Any help?
  3 个评论
Libros Construccion
Libros Construccion 2016-12-28
Sorry, didn't realized the apparent contradictory expression. But i draw differents lines, some of them reach at same points and also have the same direction. Kind of overlapped parallelism.
In the picture:
-blue number are line id (23,44,21,42)
-black number are the crossed points (23,24,25,26,27)
-RGB are the local coordinates
the code works for 23,44,21,42 because they all are parallel to global Z.
But my problem is with all() command at some cases as stated before
Libros Construccion
Libros Construccion 2016-12-28
this pictures shows a failure code case, and a operating one.
code fails at lines 13,45,15 but works on lines 39,31,33.

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2016-12-28
Based on the numbers you displayed, this looks like the standard floating-point arithmetic behavior. The == operator performs exact, down-to-the-last-bit equality testing. If you're using release R2015a or later, consider using the ismembertol function with the 'ByRows' option. If that's not an option (because you're using an older release, because you're solving a homework problem that does not allow you to use that function, or for some other reason) the answer to which I linked in my first sentence includes an alternative.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by