Skip to content
This repository has been 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

Open
SeanDS opened this issue Sep 12, 2018 · 5 comments
Open

Comments

@SeanDS
Copy link

SeanDS commented Sep 12, 2018

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.py

from slvs import *

sys = System()

# origin Point zero
p0 = 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 origin
qw, 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 vector
Workplane1 = Workplane(Point0, Normal1)


###
# triangle

p7 = 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 coincident
Constraint.on(Workplane1, Point1, Point6)
Constraint.on(Workplane1, Point2, Point3)
Constraint.on(Workplane1, Point4, Point5)

# set one side length and two angles
Constraint.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 = 1
sys.solve()
result = sys.result

if result == SLVS_RESULT_OKAY:
    print("OK")
elif result == SLVS_RESULT_INCONSISTENT:
    print("solve failed")
    print("SLVS_RESULT_INCONSISTENT")
elif result == SLVS_RESULT_DIDNT_CONVERGE:
    print("solve failed")
    print("SLVS_RESULT_DIDNT_CONVERGE")
elif result == 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.

Do you have any idea what is wrong?

@KmolYuan
Copy link
Owner

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
Copy link
Author

SeanDS commented 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
Copy link

henrikh commented 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
Copy link
Owner

KmolYuan commented 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
Copy link
Author

SeanDS commented Feb 21, 2019

@KmolYuan: wow, that's cool! Looking forward to the Cython wrapper.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants