SOLVESPACE -- parametric 2d/3d CAD

(you are viewing a thread; or go back to list of threads)

slvs.h: issue constraining distance between point and workplane (by mantielero)
I am developping a wrapper for `slvs.h` for a language call Nim. It is mostly done, I am just creating some unit tests. It is working quite well, but now I am facing an issue constraining the distance between a point and a workplane, so probably I am not using it well.

The code goes as follows (the syntax feels a little bit like python, so I think it is quite understandable):
import solvespace

proc main =
# System creation
var sys = newSystem()
let wp = sys.addWorkplane( 0, 0, 100, # Origin
1, 0, 0, # u
0, 1, 0) # v

let p = sys.addPoint(200, 200, 200)

distance(p, wp, 400)
# Viewing the system definition
echo "PARAMS-------------"
for i in sys.params:
echo i

echo "ENTITES------------"
for i in sys.entities:
echo i

echo "CONSTRAINTS--------"
for i in sys.constraints:
echo i

# Solving
let res = sys.solve
echo "DOF: ", sys.getDOF
if res != rOK:
echo "Issue: res=", res
echo res
assert res == rOK

Basically I create a workplane (XY plane with a Z offset of 100) and then I add a point. I impose a "distance" constraint between the point and workplane of 400.

Later a print (echoing) the content of the system, which shows:
Param: entity=1 group=1 val=0.0
Param: entity=2 group=1 val=0.0
Param: entity=3 group=1 val=100.0
Param: entity=4 group=1 val=1.0
Param: entity=5 group=1 val=0.0
Param: entity=6 group=1 val=0.0
Param: entity=7 group=1 val=0.0
Param: entity=8 group=1 val=200.0
Param: entity=9 group=1 val=200.0
Param: entity=10 group=1 val=200.0
(h: 1, group: 1, type: 50000, wrkpl: 0, point: [0, 0, 0, 0], normal: 0, distance: 0, param: [1, 2, 3, 0])
(h: 2, group: 1, type: 60000, wrkpl: 0, point: [0, 0, 0, 0], normal: 0, distance: 0, param: [4, 5, 6, 7])
(h: 3, group: 1, type: 80000, wrkpl: 0, point: [1, 0, 0, 0], normal: 2, distance: 0, param: [0, 0, 0, 0])
(h: 4, group: 1, type: 50000, wrkpl: 0, point: [0, 0, 0, 0], normal: 0, distance: 0, param: [8, 9, 10, 0])
(h: 1, group: 1, type: 100002, wrkpl: 0, valA: 400.0, ptA: 4, ptB: 0, entityA: 3, entityB: 0, entityC: 0, entityD: 0, other: 0, other2: 0)
Looking at the params:
- 1-3: this is the workplane origin
- 4-7: this is the workplane quaternion
- 8-10: thi is the point.
The entities:
- 1: point3d
- 2: quaternion
- 3: workplane
- 4: point3d
The constraint:
- type: 100002: SLVS_C_PT_PLANE_DISTANCE
- valA: 400.0
- ptA: 4
- entityA: 3

The system shows that the DOF=0. And when I solve it, I get: SLVS_RESULT_DIDNT_CONVERGE

Any clue about what could be the reason?
Fri Dec 24 2021, 09:43:57
(no subject) (by Andrew)
A sketch on a work plane is a 2 dimensional sketch, and only needs x and y co-ordinates. Sketch anywhere in 3d is available, but is mainly useful for construction entities for such things as creating a skewed work plane..

Hope this helps.
Fri Dec 24 2021, 11:05:25
(no subject) (by mantielero)
First thanks for your answer, but I think I don't get it yet.

The documentation


The distance from point ptA to workplane entityA is equal to
valA. This is a signed distance; positive versus negative valA
correspond to a point that is above vs. below the plane.

and given that it has no start, in accordance with the documentation:
Constraints that ignore the wrkpl member are marked with no star.

My understanding is that it should work regarless of working on workplane or not.
Fri Dec 24 2021, 11:21:37
(no subject) (by Paul)
I knew there is point-on-plane, but this pt-plane-distance constraint was news to me. In the GUI I am able to create such a constraint after extruding a cube by selecting a face and a new point. In an empty sketch I am able to switch to anywhere in 3d, place a point, and can then constrain its distance to all 3 reference workplanes.

@mantielero be aware that the solver may be undergoing a huge change. Work was done several years ago (but never merged) to integrate Eigen for performance reasons, and those patches have been rebased to master in the last few days and are going through review on github. If you don't want those changes it should be fine to use the 3.0 version since the solver hasn't changed much otherwise. Also, if you have the background more eyes on the patches would be welcome.
Fri Dec 24 2021, 12:33:50
(no subject) (by Andrew)
We are deeper into the weeds than I am really comfortable with, however I refer you to the entities section of that document, where it describes both 3d points an 2d points. Aa point on the work plane only has U and V parameters, so I would suggest you try a two parameter version. Also, which may help you figure things out, a .also file can be opened in a text editor., so creating what you are trying to do in solvespace, and looking at the file may help you figure things out.
Fri Dec 24 2021, 13:54:39
(no subject) (by mantielero)
Oh god. I hope the API doesn't change much! Sadly I don't know much C or C++.

I understand what you are saying. I might end up learning how to use SolveSpace as well.

In any case, I filed a bug report.
Sat Dec 25 2021, 01:33:42
Post a reply to this comment:
Your Name:
Your Email:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):
© 2008-2021 SolveSpace contributors. Most recent update Apr 18 2021.