Part.Point vs FreeCAD.Vector and conversion

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Part.Point vs FreeCAD.Vector and conversion

Post by Cyril »

Hi,

I have been surprised to see that intersection of 2 lines return a list of points and not a list of vectors.

Code: Select all

line1 = Part.Line()
line2 = Part.Line(FreeCAD.Vector(0,0,0), FreeCAD.Vector(1,0,0))
line1.intersect(line2)[0]  # -> <Point (0,0,0) > which is a Part.Point
A vertex is a shape and you can get a corresponding vector using Part.Vertex.Point property.

But what is a Point ? Why does it exist ? Is there a better way to convert it to a vector than :

Code: Select all

# p is a Part.Point
vec = FreeCAD.Vector(p.X, p.Y, p.Z)
(I need a list of vectors to use Part.makePolygon(vectors))
Last edited by Cyril on Thu Feb 20, 2020 3:40 pm, edited 2 times in total.
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Part.Point vs FreeCAD.Vector and conversion

Post by vocx »

Cyril wrote: Thu Feb 20, 2020 2:20 pm Hi,

I have been surprised to see that intersection of 2 lines return a list of points and not a list of vectors...
You should provide a complete working example. It took me a while to understand what "line" is.

Code: Select all

line1 = Part.LineSegment(App.Vector(0,0,0), App.Vector(2,2,0))
line2 = Part.LineSegment(App.Vector(1,0,0), App.Vector(-2,2,0))
p = line1.intersect(line2)[0]
vertex = p.toShape()
vector = p.toShape().Point
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Cyril
Posts: 133
Joined: Wed Aug 23, 2017 5:04 pm
Location: Geneva (Switzerland)
Contact:

Re: Part.Point vs FreeCAD.Vector and conversion

Post by Cyril »

vocx wrote: Thu Feb 20, 2020 3:28 pm You should provide a complete working example. It took me a while to understand what "line" is.
My bad I thought it was obvious but it is of course not a good thing to presume anything obvious. I have edited my initial post.
vocx wrote: Thu Feb 20, 2020 3:28 pm vertex = p.toShape()
vector = p.toShape().Point
Thanks for this first answer. However I am still very interested by the "why". Isn't Part.Point redundant ? Why is it useful to have another class ?
I blog about HVAC / BIM / Energy : pythoncvc.net. If you like you can follow the RSS feed.
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Part.Point vs FreeCAD.Vector and conversion

Post by vocx »

Cyril wrote: Thu Feb 20, 2020 3:48 pm ...
Thanks for this first answer. However I am still very interested by the "why". Isn't Part.Point redundant ? Why is it useful to have another class ?
OpenCASCADE and Part Workbench magic.
Part Workbench wrote: In OpenCascade terminology, we distinguish between geometric primitives and topological shapes. A geometric primitive can be a point, a line, a circle, a plane, etc. or even some more complex types like a B-Spline curve or a surface. A shape can be a vertex, an edge, a wire, a face, a solid or a compound of other shapes. The geometric primitives are not made to be directly displayed on the 3D scene, but rather to be used as building geometry for shapes. For example, an edge can be constructed from a line or from a portion of a circle.

In summary, geometry primitives are "shapeless" building blocks, while topological shapes are the real objects built on them.

A complete list of all primitives and shapes refer to the OCC documentation ... and search for Geom_* (for geometric primitives) and TopoDS_* (for shapes). There you can also read more about the differences between them.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply