[Free-cad-general] Understanding Vector in Python Script From: Bernard - 2013-04-04 23:19 ```Hi, I am trying to understand how Base.Vector.add() works. I cannot understand why a result has twice the value of what I am expecting: import FreeCAD from FreeCAD import Base from FreeCAD import Part def WIDTH(): return 6.5 def HEIGHT(): return 3 def createBox(): vector1 = Base.Vector(WIDTH(), HEIGHT() / 2, 0) vector2 = vector1.add(Base.Vector(- WIDTH(), 0, 0)) # I expected vector3 to be at the same distance from the x axis as vector1 and vector1, i.e. HEIGHT() / 2 vector3 = vector2.add(Base.Vector(0, -HEIGHT(), 0))# Unexpected twice the distance vector4 = vector3.add(Base.Vector(WIDTH(), 0, 0)) lineEdge1 = Part.Line(vector1, vector2).toShape() lineEdge2 = Part.Line(vector2, vector3).toShape() lineEdge3 = Part.Line(vector3, vector4).toShape() lineEdge4 = Part.Line(vector4, vector1).toShape() wire = Part.Wire([lineEdge1, lineEdge2, lineEdge3, lineEdge4]) Part.show(wire) createBox() Would anybody be able to help? Many thanks, Bernard ```
 Re: [Free-cad-general] Understanding Vector in Python Script From: Bernard - 2013-04-05 06:38 ```Hi, Found the problem. Had integer input def HEIGHT(): return 3 which results in inaccurate integer division in Python. Sorry. Bernard On Fri, 05 Apr 2013 11:19:03 +1200, you wrote: >Hi, > >I am trying to understand how Base.Vector.add() works. I cannot >understand why a result has twice the value of what I am expecting: > >import FreeCAD >from FreeCAD import Base >from FreeCAD import Part > >def WIDTH(): > return 6.5 > >def HEIGHT(): > return 3 > >def createBox(): > > vector1 = Base.Vector(WIDTH(), HEIGHT() / 2, 0) > vector2 = vector1.add(Base.Vector(- WIDTH(), 0, 0)) > # I expected vector3 to be at the same distance from the x axis as >vector1 and vector1, i.e. HEIGHT() / 2 > vector3 = vector2.add(Base.Vector(0, -HEIGHT(), 0))# Unexpected >twice the distance > vector4 = vector3.add(Base.Vector(WIDTH(), 0, 0)) > > lineEdge1 = Part.Line(vector1, vector2).toShape() > lineEdge2 = Part.Line(vector2, vector3).toShape() > lineEdge3 = Part.Line(vector3, vector4).toShape() > lineEdge4 = Part.Line(vector4, vector1).toShape() > > wire = Part.Wire([lineEdge1, lineEdge2, lineEdge3, lineEdge4]) > Part.show(wire) > >createBox() > > >Would anybody be able to help? > >Many thanks, > >Bernard > > >------------------------------------------------------------------------------ >Minimize network downtime and maximize team effectiveness. >Reduce network management and security costs.Learn how to hire >the most talented Cisco Certified professionals. Visit the >Employer Resources Portal >http://www.cisco.com/web/learning/employer_resources/index.html >_______________________________________________ >Free-cad-general mailing list >Free-cad-general@... >https://lists.sourceforge.net/lists/listinfo/free-cad-general ```
 Re: [Free-cad-general] Understanding Vector in Python Script From: Werner Mayer - 2013-04-05 07:57 ```Hi Bernard, to avoid such kind of problems you can load a special Python module. Example: >> 3/2 # gives 1 >> from __future__ import division >> 3/2 # now gives 1.5 Hope this helps. Regards, Werner On 05.04.2013 08:22, Bernard wrote: > Hi, > > Found the problem. Had integer input > def HEIGHT(): > return 3 > > which results in inaccurate integer division in Python. > > Sorry. > > Bernard > > > On Fri, 05 Apr 2013 11:19:03 +1200, you wrote: > >> Hi, >> >> I am trying to understand how Base.Vector.add() works. I cannot >> understand why a result has twice the value of what I am expecting: >> >> import FreeCAD > >from FreeCAD import Base > >from FreeCAD import Part >> def WIDTH(): >> return 6.5 >> >> def HEIGHT(): >> return 3 >> >> def createBox(): >> >> vector1 = Base.Vector(WIDTH(), HEIGHT() / 2, 0) >> vector2 = vector1.add(Base.Vector(- WIDTH(), 0, 0)) >> # I expected vector3 to be at the same distance from the x axis as >> vector1 and vector1, i.e. HEIGHT() / 2 >> vector3 = vector2.add(Base.Vector(0, -HEIGHT(), 0))# Unexpected >> twice the distance >> vector4 = vector3.add(Base.Vector(WIDTH(), 0, 0)) >> >> lineEdge1 = Part.Line(vector1, vector2).toShape() >> lineEdge2 = Part.Line(vector2, vector3).toShape() >> lineEdge3 = Part.Line(vector3, vector4).toShape() >> lineEdge4 = Part.Line(vector4, vector1).toShape() >> >> wire = Part.Wire([lineEdge1, lineEdge2, lineEdge3, lineEdge4]) >> Part.show(wire) >> >> createBox() >> >> >> Would anybody be able to help? >> >> Many thanks, >> >> Bernard >> >> >> ------------------------------------------------------------------------------ >> Minimize network downtime and maximize team effectiveness. >> Reduce network management and security costs.Learn how to hire >> the most talented Cisco Certified professionals. Visit the >> Employer Resources Portal >> http://www.cisco.com/web/learning/employer_resources/index.html >> _______________________________________________ >> Free-cad-general mailing list >> Free-cad-general@... >> https://lists.sourceforge.net/lists/listinfo/free-cad-general > > ------------------------------------------------------------------------------ > Minimize network downtime and maximize team effectiveness. > Reduce network management and security costs.Learn how to hire > the most talented Cisco Certified professionals. Visit the > Employer Resources Portal > http://www.cisco.com/web/learning/employer_resources/index.html > _______________________________________________ > Free-cad-general mailing list > Free-cad-general@... > https://lists.sourceforge.net/lists/listinfo/free-cad-general > ```