Issues / Questions by the use of vectors (Vectro3D)

Schlagworte:
  • Vector3D
  • PythonParts

Hi dear community,

I am attempting to utilize vectors to construct a PythonPart. My goal in the current step is to create a collection of 3D-lines (the lines are axis for the reinforcement), within the coordinates of the red plane, as you see in the screenshot.

# get the x-vector of the plane
vector_x = plane.CalcPlaneVectors()[0]
# get the y-vector of the plane
vector_y = plane.CalcPlaneVectors()[1]

# get the x-vector in particular length and direction
vector_p0_p1 = vector_x
vector_p0_p1.Reverse()
vector_p0_p1.Normalize(length1)

# get the x-vector in particular length and direction
vector_p1_p2 = vector_y
vector_p1_p2.Reverse()
vector_p1_p2.Normalize(length2)

# create the point by moving the point
p1 = AllplanGeo.Move(p0, vector_p0_p1)
p2 = AllplanGeo.Move(p1, vector_p1_p2)

# create a line
line_1 = AllplanGeo.Line3D(p2, p1)

If I follow this structure and create more points and lines, they do not appear correctly and exhibit strange behavior. I am not sure whether it makes sense to provide the entire example, as I have a feeling that I might be generally doing something wrong.
I would be really grateful if you could first answer the following general questions:

Question Nr. 1:
why I cant create a new vector by creating a new instance?

# it doesnt work
vector_y_normalized = vector_y.Normalize(200)

# it works
vector_y_normalized = AllplanGeo.Vector3D(vector_y)
vector_y_normalized.Normalize(200)

# it works
vector_y_normalized = vector_y
vector_y_normalized.Normalize(200)

Question Nr. 2:
Do exist other functions to copy/move elements along the vector?

Question Nr. 3:
What it would the proper/easier way to do the step with creating 3D-lines in a coordinate system of a plane?

Thank you in advance for your answers.

Greeting
Taras Kozak

Anhänge (1)

Typ: image/png
33-mal heruntergeladen
Größe: 516,68 KiB

Question #1:
Third example doesn't work, because after that vector_y is also normalized!

vector_y_normalized = vector_y
does NOT make a copy of the instance!
Python’s rules for referencing objects with variables still apply here: assigning an object to a variable,
be it a class object or an instance, does not create a distinct copy of that object.
The variable merely references that object, serving only as an alias for it.

You need to make e deep copy or use first example:

vector_y_normalized = AllplanGeo.Vector3D(vector_y)
This may have triggered your problems.

Question #2:
This function not exist!
But you can create division points on a curve (Line2D, Polyline2D, Arc2D, Spline2D, Clothoid2D),
and then construct new geometric elements at these points! maybe it's necessary to calculate the tangents
at this division points to get the right direction at this specific point. (if curve is a acr, spline or clothoid)

Question #3:
If you have a plan, then you can get the transformation matrix from it:
matrix = plane.GetTransformationMatrix()

This matrix contains the transformation of points in the plane to the origin.

So you can construct your Lines at the origin:

Line3D line=AllplanGEo.Line3D()
line.SetStartPoint(AllplanGeo.Point3D(0,0))
line.SetEndPoint(AllplanGeo.Point3D(1000,0))
an the transform it back to the plane.
For that we need to invert the transformation matrix, so the the inv_matrix conatins the transformation
from origin to plane:
inv_matrix=AllplanGeo.Matrix3D(matrix)
inv_matrix.GaussInvert()
Then do the transformation:
line_in_plane = AllplanGeo.Transform(line, inv_matrix)

or
line *= inv_matrix  #be carefully -> this modifies the line directly
Thats it! Maybe you should read about instances in python to avoid problems with that in the future!
Good luck!

@Nemo
thank you a lot for the very very quick answer at that time! With your tip I could simplify the PythonPart by many times.

P.S. GaussInvert was not necessary.