CadQuery / CadQuery/cadquery

Sketch solver does not converge Angle constraint with bad starting point

Open
#960 2 comments 0 reactions 0 assignees View on GitHub
sketching
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

Example of "bad" or problematic starting point:

```
.segment((0, 0), (1.0, 0), "seg1")
.segment((0, 0), (-1.0, 0.0), "seg2")
.constrain("seg1", "seg2", "Angle", 30)
```

Another example with segment-arc when tangents are opposite:
```
.segment((-0.5, -2), (-0.5, 0.0), "seg1")
.arc((-0.5, 0.0), (0.0, -0.5), (0.5, 0.0), "arc1")
.constrain("seg1", "arc1", "Coincident", None)
.constrain("seg1", "arc1", "Angle", 30)
```

Starting point before solve:
![image](https://user-images.githubusercontent.com/16394272/149662552-ffad47a9-ca6e-41fd-a3b9-03c0b415819e.png)

I'm testing a fix for this issue by checking if the tangent vectors are opposite, then rotating one of the vectors to push the optimizer in one direction (maybe need to check parallel for other cases):
```
if v1.IsOpposite(v2,TOL/2):
v1 = v1.Rotated(TOL)
```

So far this appears to be working in my testing.

![image](https://user-images.githubusercontent.com/16394272/149662717-150f6dfe-c7be-49d0-ada8-d7e4ef464886.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.