FreeCAD Vector() is a "point in space" or an "oriented segment"?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by onekk »

Sorry for this post, as it could create more confusion in some minds than eplain some thing.

A Vector in matehmatics is an "oriented segment" with some properties.

a Vector in FreeCAD behave more like a "point in space" in other word a "coordinate".

BUT:

it has some properties like Length, that is more similar to the "magnitude"

but in mathematics a Vector has also a "direction"

Plus almost all the math operations on Vector are exposed as methods of a Vector entity.

So some question need to be explained, at least for many people like me that are not "math genius".

A FreeCAD Vector has a "direction"?

I could think of the concept of the "oriented segment" if I wrote:

Code: Select all

myVect = Vector(10,0,10) # "a point in space"

or_seg = Part.LineSegment(Vector(0,0,0), myVec)

Could kindly anyone more skilled than me explain in a better way such thing.

Only to know better things, and maybe resolve some other people doubt:

TIA and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by Chris_G »

To me, a FreeCAD vector is both a point in space, and a vector from origin to this point.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by onekk »

Thanks @Chris_G, but as an "oriented segment", there is a method to obtain the "direction"?

TIA and Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by ickby »

A FreeCAD vector is just a triplet of numbers, you can interpret those however you want. Therefore the interpretation depends very much on the api of the functions accepting vectors. Sometimes they excepts a vector as a description for a point in space, sometimes as a direction. If you want to use the vector as direction it can be helpful to normalize by using "normalize" method of vector.
Paula
Posts: 48
Joined: Tue Jan 26, 2021 10:06 pm

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by Paula »

Even though it contains just an x, y and z value, a vector is not a point in space because those values don't represent the distance from the origin like they would for a point.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by onekk »

Paula wrote: Sun May 30, 2021 6:22 pm Even though it contains just an x, y and z value, a vector is not a point in space because those values don't represent the distance from the origin like they would for a point.

Code: Select all

p1 = Vector(10,10,0)

print(p1.Length)

14.142135623730951
This is the distance from origin, or "magnitude", note that I'va not specified anything other than the coordinates of the Vector().

plus:

Code: Select all

print(dir(p1))

among others:

 'add', 'cross', 'distanceToLine', 'distanceToLineSegment', 'distanceToPlane', 'distanceToPoint', 'dot', 'getAngle', 'isEqual', 'isOnLineSegment', 'multiply', 'negative', 'normalize', 'projectToLine', 'projectToPlane', 'scale', 'sub', 'x', 'y', 'z']

For what I've done the question to clarify maybe if getAngle() is the direction intendend as in "math meaning", so maybe some more clear wiki pages could take inspiration and be more useful to those know mathematics (sadly I'm not very trained in maths).


Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Paula
Posts: 48
Joined: Tue Jan 26, 2021 10:06 pm

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by Paula »

Hi Carlo
onekk wrote: Sun May 30, 2021 6:30 pm
Paula wrote: Sun May 30, 2021 6:22 pm Even though it contains just an x, y and z value, a vector is not a point in space because those values don't represent the distance from the origin like they would for a point.

Code: Select all

p1 = Vector(10,10,0)

print(p1.Length)

14.142135623730951
This is the distance from origin, or "magnitude", note that I'va not specified anything other than the coordinates of the Vector().
Err no. It's not the distance from the origin. It's just a value which in FreeCAD represents a length. A 14.142mm line is a 14.142mm line regardless of where you place it with respect to the origin. Whilst in a CAD application the vector magnitude will usually represent a line or distance it could equally represent something different in an application. For instance if I walk in a certain direction at a certain speed I can represent that with a vector. The vector contains no information about my starting point or end point; it's just my speed and direction of travel.

onekk wrote: Sun May 30, 2021 6:30 pm

plus:

Code: Select all

print(dir(p1))

among others:

 'add', 'cross', 'distanceToLine', 'distanceToLineSegment', 'distanceToPlane', 'distanceToPoint', 'dot', 'getAngle', 'isEqual', 'isOnLineSegment', 'multiply', 'negative', 'normalize', 'projectToLine', 'projectToPlane', 'scale', 'sub', 'x', 'y', 'z']

For what I've done the question to clarify maybe if getAngle() is the direction intendend as in "math meaning", so maybe some more clear wiki pages could take inspiration and be more useful to those know mathematics (sadly I'm not very trained in maths).
Looking at the c++ code, getAngle() returns the angle between two vectors so no it doesn't return the direction of the vector. That would actually require three angles for the x, y and z directions respectively.
edwilliams16
Veteran
Posts: 3108
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by edwilliams16 »

Maybe my page https://wiki.freecadweb.org/Sandbox:Edw ... in_FreeCAD may help.

A vector is a quantity that has both magnitude and direction. Examples are displacement "2 km NorthEast" or velocity "10 m/sec upward" or force "10 Newtons towards the oak tree", or acceleration " 1 meter/sec/sec towards the center of the circle".

Given a coordinate system (x/y/z axes) any vector can be split into three components along the axes. For instance, 2 km NE can be expressed as (1.414, 1.414, 0) - i.e go 1.414 km E, then 1.414 km N then 0 km up to end up at the given point.
Three numbers represent the vector in a given coordinate system. In a different coordinate system the numbers change. If our x-axis was NE, the y-axis NW, and z upward, the same vector would be (2, 0 ,0). Rotations do the math for you when changing coordinate systems.

The length of our example vector is 2 km. This will be true whatever coordinate system we use to represent it.

The direction of our vector is NE - we can't describe that without a coordinate system. A vector of any (non-zero) length in the NE direction could be used to represent that direction, but for the sake of definiteness it is customary to normalize it by making it unit length (by dividing it by its length). In FreeCAD, this is often done for the internal representation - the user can use any vector in the desired direction.

Directions are useful in FreeCAD to represent rotation axes.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by onekk »

Fist af all Thanks and Regards to all partecipants.

@Paula, I don't want to begin a flame war nor make any personal offense to you, it's only for clarity.

As I'm not very skilled in math, but I'm using FreeCAD almost daily using mostly Scripting where concepts and math became "very important" if not "vital", I have some concepts, maybe very wrong, so clarify primarily my mind.

But for my mental sanity, to honor the original scope of this post, which was to gather better explanation of a base concept that seems to have many misunderstanding if you read many forum posts.

From edwilliam16 explanation:
The length of the vector v1 is given by Pythagoras' theorem (in 3D):

Code: Select all

import math 
math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z)


but the first result of a internet search of "vector magnitude" give this result.

https://mathinsight.org/definition/magnitude_vector

So if my rusted math is not too wrong, the formulas, seems very much similar, so your assumption is not in line with that explanation.


From what I could guess as you are dealing with coordinates, and numbers are starting by 0, so the origin of a Vector is "implicitly" the origin Vector(0,0,0)

Or maybe I'm doing some wrong assumptions?

I know also that Vector has a slightly different concepts when used in Physics (the force and speed are physics concepts) maybe this is one of the sources of confusion, at least for me and from many forum post also for other people.

The situation is even worse as in FreeCAD vector is used also for rotation, where it resemble simply to a collection of "rotation number" when entered, but became a different thing when is used as output of some methods.

Not forgetting of the "orientation plane" when used as Vector(0,0,1) to set the orientation in space of a 2D curve, as circle and so on.

For all these different conceptsI have created this post, hoping that more competent people than me could gave some explanation that maybe could became a better documentation not only for beginners but also for more advanced user.

@edwilliams16 there is some chances that your page will became a wiki page soon?

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Brutha
Posts: 221
Joined: Mon May 04, 2015 1:50 pm

Re: FreeCAD Vector() is a "point in space" or an "oriented segment"?

Post by Brutha »

Perhaps think of it like this: the 3 numbers are magnitudes, not co-ordinates.

So, vector(2,0,0) is a vector of magnitude 2 pointing along the x axis.
Post Reply