Having problems with 'all' command
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Libros Construccion
il 28 Dic 2016
Commentato: Libros Construccion
il 28 Dic 2016
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 Commenti
Risposta accettata
Steven Lord
il 28 Dic 2016
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!