# Valid Vector3d endpoint in all directions? [Solved]

[[Solved]]: Yes, after testing it appears that it is so.

Will this always give med a valid (vector) endpoint, anywhere in any direction in the world coordinate system?

Given a unit vector ‘`vect`’ and a ‘`start_pt`’ and a vector length ‘`Len`’:

``````Dim end_pt As New Point3d

end_pt = start_pt + (vect * Len)
``````

… which, I assume, will result in the same line (with the same endpoint) as :

``````Dim Ln As New Line(start_pt, vect, Len)
``````

Is that correct? I want to re-use an existing endpoint in a loop, instead of recreating it a zillion times.

Or are there better/faster ways to get the vector endpoint?

// Rolf

Yes, a point lying on the surface of a sphere centered at start_pt with radius Len

I think I don’t understand what is fixed and what varies here …
… And what you are going to re-use …

Ops, sorry. The for-loop “`0..zillion`” times was missing. With Point or Line, New or “reused” variable, in a for-loop:

``````Dim line As New Line
Dim end_pt As New Point3d

For Each start_pt in points
end_pt = start_pt + (vect * Len)              ' <- Settled for this
' or
line.From = start_pt
line.To = end_pt = start_pt + (vect * Len)
' ...
Next
``````

and

``````For Each start_pt in points
Dim line As New Line(start_pt, vect, Len)
' or
Dim end_pt As New Point3d(start_pt + (vect * Len))
' ...
Next
``````

That must have looked confusing without this context, sorry.

I had used the “convenient syntax” “`Dim Ln As New Line(start_pt, vect, Len)`”, which doesn’t expose the “magic” of how the end point is actually created, but with the extra burden of creating a new point or line each time (which I originally had use for in the code, but now I was out for the most optimized code).

Anyway, it seems that the end_pt becomes correct in any direction, in the entire 3D space (strange phenomenons of flipping etc happened in another case when rotating planes in 3D space, hence the question mark… ).

// Rolf

Thanks for explaining !

Yes, from the code, it looks like the line might be useless, if what you need is just the point …

Also, in RhinoCommon, Point3d, Vector3d and Line are structures, not classes.
That should make then quite cheap on resources anyway.

Here, as I understand it, you create a point and a vector for any iteration,
which, as I already said, should not be so slow …

Only way that I know to even avoid to create these objects (structures) is working direclty with coordinates

e.g.

``````end_pt.X = start_pt.X + vect.X * Len
end_pt.Y = start_pt.Y + vect.Y * Len
end_pt.Z = start_pt.Z + vect.Z * Len
``````

… but I have no idea whether this might be faster … or even slower … sorry

I think planes in RC have to be taken with caution …
Actually in Rhino planes are two-fold.They are simple planes, but they are also used as reference systems (or frames).
and often (IMO) is not clear in which way they are taken, this can be confusing.

I think the flipping you’re talking about might happen when the plane is considered … just a simple plane. That is a point and a normal, without a side and without X and Y axes.
In this context, I think that the plane ‘cannot’ flip. I mean … it’s always the same plane. A simple plane has no orientation.
But if here we assume that it is a frame, with its three axes, we might be going into troulbes …

It might be safer, when in doubt, working directly with a point and two vectors (origin, Xaxis, Yaxis) , and then build a plane from them when needed …
( This is only my personal … scripter opinion … )

1 Like

Exactly, that is good advice. Very good advice. Thanks. I will definitly try that approach now when I’m getting closer to putting things together.

I actually was thinking of trying to use only vectors and try the old test again (the one with planes that flipped like crazy) to see if I can get rid of the flippin’. Well, I’m quite sure of that the flippin’ will be gone if using only the pont and two vectors as you suggest (thank’s for helping me to make that thought take concrete form) since the vectors proved to have no such problems with the orientation when I tried twisting and moving them around.

Good. Now I have a plan. Always good to talk to you. I learn a lot.

// Rolf

Nice place indeed here.
Many opportunities to learn from professional programmers like you, Menno and all the others on the forum.