SolveSpace Logo SOLVESPACE -- parametric 2d/3d CAD
Examples
Tutorials
Features
Download
Reference
Technology
Library
Forum
Contact
USER FORUM

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

New constraint "Length Difference" (by ruevs)
Hi,

First of all - great program Jonathan! I've been a fan for more than two years.

Now I finally decided to contribute something. It is a new constraint "Length Difference" - it constrains the lengths of two line segments to differ by a constant.

The code is here: https://github.com/ruevs/solve...78449fa8035b403b7abc6db355c551

My reasoning for adding this new constraint is that When making models I always try to make them parametric in parts where it makes sense. There was a discussion about this here on the forum http://solvespace.com/forum.pl?action=viewthread&parent=211

One of the common problems is making a parametric joint. For example in sheet material where you want the material thickness to be a parameter and want a certain tolerance between the "mortice" and "tenon" (https://en.wikipedia.org/wiki/Woodworking_joints).

The new constraint allows this to be done more conveniently. See the attached example - it also contains solvespace.exe built from my fork.

This is not an ideal solution - it does not allow the tolerance itself to be a parameter for example. But it was very simple to implement.

In my opinion an ideal solution would be to allow using entity (constraint) names as parameters in the formulas that the user can already enter when defining a dimension. A bit like "whitequark" added "Pi" (here: https://github.com/whitequark/...b89d76fdd79ded845cdf3dbde4ecef) but much more advanced. The formula will need to be saved in the file instead of evaluated to a constant immediately. For example something like:
"2 * c002 + c003"
for a new dimension, where c002 and c002 are existing constraints that have a type "length". This is what I intended to implement initially but I realized that I will need to understand the code very well before I could do it.

The above feature on the other hand was an hour job starting with "git clone" and using cmake for the first time in my life :-)

I forked the "Evil-Spirit | for-upstream" branch because it seems to have the most changes (his "lathe" looks quite experimental at this point). If you are interested in merging this feature but not the other stuff from "whitequark" and "Evil-Spirit" - I think it is very good stuff - I could send you a pull request against your master branch.

Best regards,
Peter
Tue Oct 27 2015, 04:45:45, download attachment LengthDifferenceExampleAndExe.zip
(no subject) (by Jonathan Westhues)
Makes sense, and I'll take a look (though note that "LNEGTH" is systematically misspelled...).

It's not by accident that the expression parser uses the same data structures as the constraint solver; I'd always intended to allow dimensions to refer not only to other constants, but also to unknown expressions for the solver. That's a much bigger job, of course.
Tue Oct 27 2015, 05:12:36
(no subject) (by ruevs)
"LNEGTH" :-) Sorry - once I typed it wrong when defining it sketch.h it was all over :-)

I amended the commit. Hopefully no one will refer to the old one.

The new one is:
https://github.com/ruevs/solve...d1e17ed5d5bbe8cd42fc73c8326f7c
Tue Oct 27 2015, 07:57:20
(no subject) (by EvilSpirit)
if you want to have some advices about implementing feature with expressions, you can contact me, i can give you some assist.
Sat Oct 31 2015, 05:43:23
(no subject) (by whitequark)
Hi ruevs,

Would you like me to merge your changes in my fork, with the eventual intent to upstream them?
Tue Nov 3 2015, 06:46:16
(no subject) (by ruevs)
When I have some time again I will look into implementing the dimension expressions and will contact you.

In the meantime:
https://github.com/Evil-Spirit/solvespace/pull/1
Tue Nov 3 2015, 08:43:28
(no subject) (by ruevs)
Hi Whitequark,

Just after creating the pull request above I saw your message.

Of course I would like you to! Go right ahead. I think it would be great if Jonathan has a single repository to look into for merging upstream instead of three.
Tue Nov 3 2015, 08:51:27
(no subject) (by whitequark)
ruevs,

I've merged your changes (also the mingw on windows fix) with minor differences. Primarily I have changed the shortcut to Alt+Z, since Shift+[constraint] means "add a reference constraint" elsewhere already and it seemed more confusing than introducing another modifier key instead.

Your code is good; I would really like to see more changesets from you!
Wed Nov 4 2015, 03:41:10
(no subject) (by ruevs)
Thanks!

Making the keyboard shortcut Alt+Z makes sense. I pulled your branch, however for some reason the Alt+Z accelerator does not work for me (Win XP, 32 bit). The Shift-Z did...
Wed Nov 4 2015, 08:04:37
(no subject) (by Jonathan Westhues)
Windows wants to interpret Alt+anything as a menu accelerator, and grabs the event for itself. Pick an unmodified single letter, perhaps with limited mnemonic value, analogous to the existing constraints?
Wed Nov 4 2015, 12:21:48
(no subject) (by whitequark)
Ah, that's why there are no Alt+ shortcuts. It's now 'J'.
Thu Nov 5 2015, 00:10:26
(no subject) (by whitequark)
ruevs, by the way, Appveyor lets you download the resulting executable for every build it runs and I made them compatible with Windows XP again: e.g. try https://ci.appveyor.com/projec...espace/build/2.1.163/artifacts.
Thu Nov 5 2015, 00:59:01
'J' it is! (by ruevs)
'J' it is. I'm perfectly fine with that.

The "limited mnemonic value" is what prompted me to use Shift+Z initially - all the "good mnemonic value" letters were taken :-) But I agree that not colliding with the "shift = construction" convention is more important.

Your Appveyor build works fine for me. By the way an interesting observation:
My MinGW build: 1,855,601 bytes
Appveyor 2.1.163: 2,418,176 bytes
does it build in debug mode?
Thu Nov 5 2015, 04:35:35
(no subject) (by ruevs)
Clearly it is in debug... ignore the stupid question.
Thu Nov 5 2015, 04:39:12
Further refinement (by Eikka)
A similiar ratio constraint for angles would be handy for simulating rudimentary gear trains and hinges.
Thu Feb 4 2016, 15:53:41
(no subject) (by EvilSpirit)
Yes, i've already implemented such thing and used it for gears. But it's not needed implement it separately, but in complex - just make able expression parser to write equations for solver and define some parameters. This is simple as define one more constraint.
Sat Feb 6 2016, 00:01:21
(no subject) (by ruevs)
Ehhh 5 years later we have arc length ratio/difference, but still no "expressions" a.k.a "parametric constraints"
https://github.com/solvespace/solvespace/pull/1062
https://github.com/solvespace/solvespace/issues/77
Sun Oct 10 2021, 03:24:40
(no subject) (by Paul)
@ruevs if we merge the Evil Spirit patches to include named variables, a bunch of issues immediately surface. How do you write "x=5"? What is the scope of a variable? People will want complicated scope, and they'll want hierarchical sketches. Handling that well IMHO involves several important internal changes.

I'd like to see it happen too.
Sun Oct 10 2021, 13:31:29
(no subject) (by ruevs)
You are absolutely right. My comment was not a criticism, I just found this thread searching for "gear". :-)
Mon Oct 11 2021, 09:01:33
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):
© 2008-2022 SolveSpace contributors. Most recent update June 2 2022.