You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 20, 2019. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 20, 2019. It is now read-only.
Triangle can't be solved with two angles and one distance constraint #4
Hi, I'm playing around with python-solvespace and it's great so far - thanks! One problem I found though is that it can't seem to solve the following file:
# adapted from https://github.com/KmolYuan/python-solvespace/blob/master/example/PyDemo.pyfromslvsimport*sys=System()
# origin Point zerop0=sys.add_param(0.0)
p1=sys.add_param(0.0)
p2=sys.add_param(0.0)
Point0=Point3d(p0, p1, p2)
# create normal vector# quaternion represents a plane through the originqw, qx, qy, qz=Slvs_MakeQuaternion(1, 0, 0, 0, 1, 0)
p3=sys.add_param(qw)
p4=sys.add_param(qx)
p5=sys.add_param(qy)
p6=sys.add_param(qz)
Normal1=Normal3d(p3, p4, p5, p6)
# create workplane (a plane to draw 2D points on), defined by# the origin point and the normal vectorWorkplane1=Workplane(Point0, Normal1)
#### trianglep7=sys.add_param(-22.92)
p8=sys.add_param(-6.77)
Point1=Point2d(Workplane1, p7, p8)
p9=sys.add_param(25.55)
p10=sys.add_param(-19.02)
Point2=Point2d(Workplane1, p9, p10)
p11=sys.add_param(25.55)
p12=sys.add_param(-19.02)
Point3=Point2d(Workplane1, p11, p12)
p13=sys.add_param(11.92)
p14=sys.add_param(29.07)
Point4=Point2d(Workplane1, p13, p14)
p15=sys.add_param(11.92)
p16=sys.add_param(29.07)
Point5=Point2d(Workplane1, p15, p16)
p17=sys.add_param(-22.92)
p18=sys.add_param(-6.77)
Point6=Point2d(Workplane1, p17, p18)
Line1=LineSegment2d(Workplane1, Point1, Point2)
Line2=LineSegment2d(Workplane1, Point3, Point4)
Line3=LineSegment2d(Workplane1, Point5, Point6)
# constrain edges of lines at each vertex to be coincidentConstraint.on(Workplane1, Point1, Point6)
Constraint.on(Workplane1, Point2, Point3)
Constraint.on(Workplane1, Point4, Point5)
# set one side length and two anglesConstraint.distance(50, Workplane1, Point1, Point2)
Constraint.angle(Workplane1, 60, Line1, Line2)
Constraint.angle(Workplane1, 60, Line2, Line3)
# alternatively, set two distances and one angle#Constraint.distance(50, Workplane1, Point1, Point2)#Constraint.distance(50, Workplane1, Point3, Point4)#Constraint.angle(Workplane1, 60, Line2, Line3)sys.calculateFaileds=1sys.solve()
result=sys.resultifresult==SLVS_RESULT_OKAY:
print("OK")
elifresult==SLVS_RESULT_INCONSISTENT:
print("solve failed")
print("SLVS_RESULT_INCONSISTENT")
elifresult==SLVS_RESULT_DIDNT_CONVERGE:
print("solve failed")
print("SLVS_RESULT_DIDNT_CONVERGE")
elifresult==SLVS_RESULT_TOO_MANY_UNKNOWNS:
print("solve failed")
print("SLVS_RESULT_TOO_MANY_UNKNOWNS")
print("{} DOF".format(sys.dof))
This is a triangle with two constrained angles and one constrained length, and should therefore be fully constrained. Instead, I get the error "SLVS_RESULT_DIDNT_CONVERGE". In the SolveSpace GUI it is able to solve this as "OK".
Interestingly, setting two distance constraints and one angle constraint seems to work ok.
There might be some tricks about the program side than user interface. Technically, two line elements can use same point element as theirs joint without "same point" constraint. And some times the constraints should be increased or simplified.
Thanks. I looked at the file saved by the SolveSpace GUI for this problem and identified the constraints it defines. It seems like it only constrains the points to be coincident, the line lengths and angles, and the fact that some of the points were dragged. This seems to be the same as what I define in my script above. Unfortunately I can't find anything different compared to how the GUI does it...
I just noticed this discussion. There is an "other" property which belongs to the angle constraint. This is used to tell in which direction the angle is measure between two lines. If this could be exported in the Python API, then it would be possible to work with constraints like this.
Activity
KmolYuan commentedon Sep 17, 2018
There might be some tricks about the program side than user interface. Technically, two line elements can use same point element as theirs joint without "same point" constraint. And some times the constraints should be increased or simplified.
SeanDS commentedon Sep 21, 2018
Thanks. I looked at the file saved by the SolveSpace GUI for this problem and identified the constraints it defines. It seems like it only constrains the points to be coincident, the line lengths and angles, and the fact that some of the points were dragged. This seems to be the same as what I define in my script above. Unfortunately I can't find anything different compared to how the GUI does it...
henrikh commentedon Feb 21, 2019
I just noticed this discussion. There is an "other" property which belongs to the angle constraint. This is used to tell in which direction the angle is measure between two lines. If this could be exported in the Python API, then it would be possible to work with constraints like this.
KmolYuan commentedon Feb 21, 2019
@henrikh I was actually re-disigned a new wrapper with Cython. And the SWIG wrapper might be deprecated after new wrapper has fully tested.
The structure that exported in wrapper:
https://github.com/KmolYuan/python-solvespace/blob/master/Cython/slvs.pxd#L90-L103
But the guide function ignored the "other" parameters, so it should be replaced by a new function:
https://github.com/KmolYuan/python-solvespace/blob/master/Cython/slvs.pxd#L194-L204
The progress of Cython wrapper still left constraint methods and unit test scripts. I expect next week to finish these part.
SeanDS commentedon Feb 21, 2019
@KmolYuan: wow, that's cool! Looking forward to the Cython wrapper.