Parallel vectors in dynamo - isolating them

I have a list of vectors taken from a room outline (in purple). I only want 1 instance of each vector. I also want to remove any vectors that are parallel to each other.

I’ve tried it several ways, all pretty contrived. This is the best one so far, but still hideous. Can anyone improve this please?

Making sure I understand this right, the result of pruning the parallel vectors would mean that the three non-endpoint dots in the bottom left would be simplified to one vector?

List.UniqueItems should work on a vector list.

EDIT: Huh. Learned something new (apparently it doesn’t). You can convert the vector list to a string list first before running List.UniqueItems.

That particular list should end up with 3 items.

I tried the unique items and also tried converting to string…
Still didn’t get it down to 3. Tried about 1000 other things too :laughing:

Three? Are those intended to be orthogonal lines except for that chamfered top left?

Visually I would have expected five vectors.

It’s a rectangle room with one angle.
So one for the lines on the x-x axis, one vector for the lines on the y-y axis and one vector for the sloping angle line.

I see, the angle of the preview geometry threw me off.

Without seeing your attempt at uniqueitems I’m not sure what might still be the issue, but here’s a sample of what I tried:

Keep in mind that some of the vectors are reverses of other vectors. Parallel walls can have opposing vectors.

TEMP.dyn (41.0 KB)

Dunno if that’ll work. I think the data.remember may hold onto the list?

It didn’t for me (this workstation has an outdated build of Dynamo), but I see that the source information was the room finish boundary. I believe the vectors for the lines generated from that node all point ‘outward’, in which case you will need to address opposing vectors for parallel lines.

The issue with the ‘unique items’ is that it ignores vectors going in opposite direction (obvs)… I want to get rid of those too.

You should have seen the mess of my graph earlier. :laughing:

[0] [0] Vector(X = 0.000, Y = 1.000, Z = 0.000, Length = 1.000)
[0] [1] Vector(X = -1.000, Y = 0.000, Z = 0.000, Length = 1.000)
[0] [2] Vector(X = -0.242, Y = -0.970, Z = 0.000, Length = 1.000)
[0] [3] Vector(X = -0.242, Y = -0.970, Z = 0.000, Length = 1.000)
[0] [4] Vector(X = 0.000, Y = -1.000, Z = 0.000, Length = 1.000)
[0] [5] Vector(X = 0.000, Y = -1.000, Z = 0.000, Length = 1.000)
[0] [6] Vector(X = 0.000, Y = -1.000, Z = 0.000, Length = 1.000)
[0] [7] Vector(X = 1.000, Y = 0.000, Z = 0.000, Length = 1.000)

They’re my normalised vectors

Possible workflow:

1.Vector.Reverse the list.
2.For the original list AND the Vector.Reverse list, generate lists of their angles about the X-axis.
3.Only take the indices from each list where angle<180.
4. You now have a modified list where vectors have been adjusted to only be within Quadrants 1 + 2 of the XY plane.
5. You should be able to do the ToString+UniqueItems workflow from here.

Not entirely sure that’s not as contrived as my original solution. :neutral_face:

I’ll give it a go tomorrow tho. :slight_smile:

Frankly, if your method logically works (your division method is doing the same quadrant check as the angular method) and doesn’t hang up from resource load, it can be as hideous as it wants to be. It still works =P. The route I proposed takes up more screenspace and isn’t addressing any logical faults yours might have.

If your concern is other users interpreting the script, annotate it up for clarity before deploying it.

1 Like

You were pretty close. Just find the unique groupings of parallel vectors.


And as @Robert_Younger mentioned, while it’s good to learn the more efficient ways to get what you want, it’s totally fine to have a lengthier process as long as it works for you.

2 Likes

That doesn’t give me 3 vectors?

More nodes = slower run time though surely?

Also… more to go wrong esp with non-OOT box nodes.

Correct. It gives you the grouped parallel vectors. From there you can just pull any one vector from each group. If the specific vector doesn’t matter then you can just pull the first item. But if you want something like the normalized positive vector then you’ll have to do some sorting first.
image

1 Like

See if this works

p3 = List.Transpose(List.DropItems(List.Sublists(p2,0..1,1),-1));
v1 = Vector.ByTwoPoints(p3[0],p3[1]).Normalized();
a1 = v1.AngleWithVector(Vector.XAxis());
a2 = Math.Round(a1==180?0:a1,3);
v2 = List.FirstItem(List.GroupByKey(v1,a2)["groups"]<1>);

vectors.dyn (28.5 KB) (ver 2.12)

3 Likes

It might with a few additional steps


vectors1.dyn (28.0 KB)

1 Like

Think the Vector.AngleWithVector could cause issues as it is the narrowest angle in both cases, so an angle of 45 degrees could mean (1,1,0) or (1,-1,0).

Vector.AngleAboutAxis removes that issue of my recollection serves right. You have to subtract 180 from values >= to 180 though.