Vectors almost parallel or almost equal

Hello Dynamo Community :slight_smile:

I want to get parallel vectors but the IsParallelTo node fails and there is no IsAlmostParallelTo node.

So i used the IsAlmostEqual node, therefore i had to make an extra list with reversed vectors and later combine lists.

But this method also fails because it has not enough tolerance:

So are there nodes for vectors that let me controle the tolerance, or do i have to go for points and use the math node:

image

Edit:

So would be nice to get this method to run with python, but it doesn´t like my tolerance input…

Hi @gerhard.p,

Add

clr.AddReference('RevitNodes')
import Revit
# Adds ToProtoType, ToRevitType geometry conversion extension methods to objects
clr.ImportExtensions(Revit.GeometryConversion)

And convert Dynamo geometry to Revit geometry

a = IN[0].ToXyz()
b = IN[1].ToXyz()
2 Likes

Hello, do your 2 vectors have the same length
if not normalize them,
if you need the directions

Cordially
christian.stan

1 Like

Thanks again alban :slight_smile:

But now i have to get this to work with lists and specific list levels :exploding_head:

First try/fail:

Vector1ListList = IN[0]
Vector2List = IN[1]
outlist = []

for Vector1List in Vector1ListList:
	for Vector1 in Vector1List:
		for Vector2 in Vector2List:
			almostEqual = Vector1.IsAlmostEqualTo(Vector2,0.01);
			outlist.append(almostEqual)

OUT = outlist

My output is a flattened version of what i want^^? :thinking:
The levels shown at the ootb node are what i would need.

With more list levels it´s now more complicated, my experimenting with python did not work out:

# Phython-Standard- und DesignScript-Bibliotheken laden
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('RevitNodes')
import Revit
# Adds ToProtoType, ToRevitType geometry conversion extension methods to objects
clr.ImportExtensions(Revit.GeometryConversion)

# Die Eingaben für diesen Block werden in Form einer Liste in den IN-Variablen gespeichert.

Vector1ListList = IN[0]
Vector2ListList = IN[1]
outlistlistlistlist = []

for Vector1List in Vector1ListList:
	outlistlistlist=[]
	for Vector2List in Vector2ListList:
		outlistlist=[]
		for Vector1 in Vector1List:
			outlist=[]
			for Vector2 in Vector2List:
				almostEqual = Vector1.IsAlmostEqualTo(Vector2,0.01);
				outlist.append(almostEqual)
		outlistlist.append(outlist)
	outlistlistlist.append(outlistlist)
outlistlistlistlist.append(outlistlistlist)
OUT = outlistlistlistlist

I’d recommend a different approach without Python if lists are all over the place. Maybe get the X/Y/Z components of the vector, round to nearest factor and you can then compare the vectors in a ‘rounded’ format. This essentially brings them into a limited number of orientations for comparison, even if they are slightly different. Groupbykey is used here to demonstrate the concept, but would not be used for uneven lists. In that case you’d need to run the list across an equals comparison for many vs 1. If you want to check for parallelism as well, I’d run two checks, one for the reversed vector. You can then run the two outcomes across an ‘or’ check to see if either direction is equal.

round vectors.dyn (22.6 KB)

2 Likes

Why are all my genius python fails always leading to a “I´d recommend a different approach” answer? :smiley:

Thank you Gavin, thats a good solution for me :slight_smile:

edit:

and here the whole thing:

1 Like

Just want to add that i could reduce this to only 5 nodes, it is much more efficient to just compare angles between Vectors! No rounding neccessary :smiley: