My vectors are being weird

I have 3 lists.

A nested list of points.
A list of vectors

A list of widths.

Each sublist of points is a point along a line which corresponds to the vector of the same index.
So sublist [0] of points are all along a line with vector at index [0]

I’m taking a random point and offsetting it by a width along that vector.

It works fine for anything in a list with an even index.
but if the list has an odd index the vector remains normalized.

Why?

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import Point, Vector
import random

# Inputs
line_vectors = IN[0]  # Vectors of the lines input
placement_points = IN[1]  # Nested list of points along the lines
widths = IN[2]  # List of widths

offset_points = []

# Debugging list
test = [] 

# Iterate through each width
for width in widths:
    # Randomly select a sublist index
    sublist_index = random.randint(0, len(placement_points) - 1)

    # Get the corresponding vector and sublist of points
    vector = line_vectors[sublist_index]
    points_sublist = placement_points[sublist_index]
    
    # Select a random point from the sublist
    random_point = random.choice(points_sublist)
    
    # Scale the vector by the width ... THIS ONLY WORKS FOR EVEN INDICIES... WHY ???? 
    offset_vector = vector.Scale(width)
    
    # Calculate the offset point
    offset_point = random_point.Add(offset_vector)
    
    # Append the offset point to the output list
    offset_points.append(offset_point)
    
    # Collect debug information
    test.append(f"Index: {sublist_index}, Vector: {vector}, Width: {width}, Offset Vector: {offset_vector}")

OUT = test

If I do this it works… but I want to know why the method above doesn’t work.

    offset_vector = Vector.ByCoordinates(vector.X * width, vector.Y * width, vector.Z * width)
    

Does it work with Vector.Scale(vector, width)?
Or vector.Scale(width, width, width)
What happens when the widths are all the same?
What happens if you set the widths to 0?
Set a seed with random.seed = 42 at the top so you can repeat the ‘random’ choices

Also if you’re into aesthetic code you could use
random.randrange(0, len(placement_points))

1 Like

Nope same output:

[0] Index: 1
Vector: Vector(X = 0.000, Y = -1.000, Z = 0.000, Length = 1.000),
Width: 950,
Offset Vector: Vector(X = 0.000, Y = -1.000, Z = 0.000, Length = 1.000)

[1] Index: 0,
Vector: Vector(X = -1.000, Y = 0.000, Z = 0.000, Length = 1.000),
Width: 400,
Offset Vector: Vector(X = -400.000, Y = 0.000, Z = 0.000, Length = 400.000)

[2] Index: 0,
Vector: Vector(X = -1.000, Y = 0.000, Z = 0.000, Length = 1.000),
Width: 800,
Offset Vector: Vector(X = -800.000, Y = 0.000, Z = 0.000, Length = 800.000)

Even indexes are happy. Odd indexes don’t work. Seems it only multiplies the X.

This one works… so am guessing the multiply isn’t very smart.

[0] Index: 2, Vector: Vector(X = 0.866, Y = 0.500, Z = 0.000, Length = 1.000), Width: 950, Offset Vector: Vector(X = 822.724, Y = 475.000, Z = 0.000, Length = 950.000)
[1] Index: 2, Vector: Vector(X = 0.866, Y = 0.500, Z = 0.000, Length = 1.000), Width: 400, Offset Vector: Vector(X = 346.410, Y = 200.000, Z = 0.000, Length = 400.000)
[2] Index: 1, Vector: Vector(X = 0.500, Y = -0.866, Z = 0.000, Length = 1.000), Width: 800, Offset Vector: Vector(X = 400.000, Y = -692.820, Z = 0.000, Length = 800.000)

I am not sure this is the case - feels like you might just be grabbing one invalid data point. Try 4 lists of 2 points formatted along the lines of Point.ByCoordinates((0..4)@L1<1>,0..1,0);, with 4 vectors along the lines of Vector.ByCoordaintes(1..4,0,0); and 4 widths along the lines of 1..4;. Run it via sandbox instead of Revit.

My odd indexes are perpendicular to the even indexes…

And it’s only multiplying the X so that explains it. (width, width) fixes it.

Also… Don’t have sandbox.

I think this is the issue at hand, but identifying WHY is the key portion missing here.

So go get it? There isn’t even an installer - you can run it off a thumb drive if memory serves. Just download, extract, double click, and use… :slight_smile:
https://dynamobuilds.

1 Like

OK, but how’s that going to fix my issue?
I always work in Revit so why would I use sandbox?

Instant confirmation of if this is a Dynamo for Revit issue within the namespace, or a Dynamo Sandbox issue. When troubleshooting if you aren’t aware of where the issue is it’s best to narrow in on where to look by reducing the scope of what we are looking at to a minimum reproducible case by eliminating variables.

Vector is a common class name, so your overloads could be borked via the imports; having sandbox there makes this 10 seconds to review via copy/paste.

1 Like

to have something else to tear your hair out too

1 Like

I ran it multiple times with no problems in Sandbox so it’s probably a namespace issue.

2 Likes