Skip to content
This repository was archived by the owner on Aug 20, 2019. It is now read-only.
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

Open
@SeanDS

Description

@SeanDS

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions