vector equal vector
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
vector equal vector
hello
is there no vector0 = vector1 function?
using vector0.x, vector0.y, vector0.z, = vector1.x, vector1.y, vector1.z
is there no vector0 = vector1 function?
using vector0.x, vector0.y, vector0.z, = vector1.x, vector1.y, vector1.z
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: vector equal vector
Hi! Are you asking about assignment or comparison?
Assuming you mean comparison, this is not as trivial as it sounds. When comparing vectors, like with floating-point numbers, one must generally compare with tolerance. For example:
PS. Quick testing revealed that FreeCAD actually includes tolerance when comparing vectors directly:
Code: Select all
vector2 = vector1 # <--- assignment
if vector2 == vector1: # <----comparison
Code: Select all
if (vector1 - vector2).Length <= tolerance:
Code: Select all
>>> vector1 = App.Vector()
>>> vector2 = App.Vector()
>>> vector1 == vector2
True
>>> vector2.x = 0.1
>>> vector1 == vector2
False
>>> vector2.x = 1e-8
>>> vector1 == vector2
True
Re: vector equal vector
thanks for response
vector2 = vector1 # <--- assignment
does not seem to work
using 0.15, for mac
vector2 = vector1 # <--- assignment
does not seem to work
using 0.15, for mac
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: vector equal vector
Please explain, how it does not work for you. What exactly do you do, what you expect, and what you get instead.E Guerra wrote:vector2 = vector1 # <--- assignment
does not seem to work
You may be interested in reading this: Is Python call-by-value or call-by-reference? Neither.
Re: vector equal vector
hi
here's most of the code in question
basically generates a closed sketch
works with above code
if vector0 = vector1 is used instead of vector0.x, vector0.y = vector1.x, vector1.y
only one line is generated: [0.0, 0.0] to [0.0, 12.00]
here's most of the code in question
Code: Select all
PORTS = {
....
'M10x1.0': ([0.0, 12.00], [05.00, 12.00], [05.00, 02.31], [05.21, 02.10], [05.55, 00.50], [08.00, 00.50], [08.00, 0.0]),
....
}
....
self.details = PORTS['M10x1.0']
vector0, vector1 = App.Vector(0.0, 0.0, 0.0), App.Vector(0.0, 0.0, 0.0)
for key, value in enumerate(self.details):
vector1.x, vector1.y = value
App.ActiveDocument.Sketch.addGeometry(Part.Line(vector0, vector1))
vector0.x, vector0.y = vector1.x, vector1.y
App.ActiveDocument.Sketch.addGeometry(Part.Line(vector0, App.Vector(0.0, 0.0, 0.0))
....
works with above code
if vector0 = vector1 is used instead of vector0.x, vector0.y = vector1.x, vector1.y
only one line is generated: [0.0, 0.0] to [0.0, 12.00]
Last edited by wmayer on Wed Feb 10, 2016 2:52 pm, edited 1 time in total.
Reason: Added code tags
Reason: Added code tags
Re: vector equal vector
It seems to me that this is your problem: (b points to a)
this way it should work: (all elements are copied)
Code: Select all
>>> a = App.Vector(1,2,3)
>>> b = a
>>> a.x = 10
>>> a
Vector (10.0, 2.0, 3.0)
>>> b
Vector (10.0, 2.0, 3.0)
Code: Select all
>>> a = App.Vector(0,1,2)
>>> b = App.Vector(a)
>>> a.x = 10
>>> b
Vector (0.0, 1.0, 2.0)
>>> a
Vector (10.0, 1.0, 2.0)
Re: vector equal vector
Additionally to what looo said the problem is that after the first iteration you have added two (equal) lines to the sketch.
When doing a
results into the behaviour that vector0 and vector1 are the one and the same object. In the second iteration the creation of the line fails because the two passed points vector0 and vector1 are equal because they are still the same object.
When doing a
Code: Select all
vector0 = vector1
Re: vector equal vector
Could anyone confirm this is really an intended approach? How big is the tolerance in such a comparison. I need to compare the direction of two edges. For the edge direction I useDeepSOIC wrote: ↑Tue Feb 09, 2016 3:24 pm When comparing vectors, like with floating-point numbers, one must generally compare with tolerance. For example:PS. Quick testing revealed that FreeCAD actually includes tolerance when comparing vectors directly:Code: Select all
if (vector1 - vector2).Length <= tolerance:
Code: Select all
>>> vector1 = App.Vector() >>> vector2 = App.Vector() >>> vector1 == vector2 True >>> vector2.x = 0.1 >>> vector1 == vector2 False >>> vector2.x = 1e-8 >>> vector1 == vector2 True
Code: Select all
e = theedgeobject
direction = e.Vertexes[1].Point - e.Vertexes[0].Point
Re: vector equal vector
When you execute the above code snippet then you will see thatCould anyone confirm this is really an intended approach? How big is the tolerance in such a comparison. I need to compare the direction of two edges. For the edge direction I use
Code: Select all
vector1 = App.Vector()
vector2 = App.Vector()
vector1 == vector2
vector2.x = 1e-8
vector1 == vector2
So, with
Code: Select all
vector2.x = 1e-15
vector1 == vector2
Code: Select all
vector2.x = 1e-16
vector1 == vector2
Now have a look at occ's Precision class. There is a function Angular() that returns the threshold of what occ considers to be parallel. This limit is 1e-12.
So with the internal limit we use in the vector class you shouldn't run into problems because of that.
Btw, maybe it makes sense to also expose the Precision functions to Python.
- DeepSOIC
- Veteran
- Posts: 7896
- Joined: Fri Aug 29, 2014 12:45 am
- Location: used to be Saint-Petersburg, Russia
Re: vector equal vector
btw, congratulations bernd!