Commit Graph

56 Commits (36182448cedd863aefb96348625dbb5b6575c3ea)

Author SHA1 Message Date
Jonathan Westhues 1692382d5a Replace the closed-form solutions for entity-entity splitting with
a method that works on the piecewise linear segments, and then
refines any intersections that it finds by Newton's method. So now
I support cubics too, and circle-circle intersections, and the code
is much simpler.

[git-p4: depot-paths = "//depot/solvespace/": change = 2012]
2009-07-07 00:21:59 -08:00
Jonathan Westhues a74f85e0d1 I had been using LENGTH_EPS as the tolerance on both xyz points and
uv points. This is inconsistent, unless the surface happens to be a
plane square with side length one.

So modify the SBspUv tests to take a surface, and measure distance
linearized in that surface. That fixes at least one
mis-classification bug, and doesn't seem to break anything.

[git-p4: depot-paths = "//depot/solvespace/": change = 2005]
2009-07-01 19:32:17 -08:00
Jonathan Westhues 4ca7548ffe Don't merge two coincident surfaces unless they share an edge.
Otherwise, we might merge in ways that make things slower (because
the bboxes aren't as tight) or less robust (because the
intersection needs to be split in more places, and that might fail).

[git-p4: depot-paths = "//depot/solvespace/": change = 2003]
2009-06-29 20:38:40 -08:00
Jonathan Westhues f865901bd2 Group edges into chains (that don't intersect edges from the other
contour, except at the ends of the chain), and classify the entire
chain. That's much faster than going edge by edge.

[git-p4: depot-paths = "//depot/solvespace/": change = 2002]
2009-06-26 21:53:56 -08:00
Jonathan Westhues cf77e51ddc I think this fixes an issue importing STEP into Rhino. Something
bad seems to happen when a trim curve's u or v coordinate goes even
slightly outside [0, 1]. And since I considered the bbox of the pwl
segments when merging coincident surfaces (and not the true
curves), that happened. So add a bit of slop, which seems to make
things happy.

[git-p4: depot-paths = "//depot/solvespace/": change = 1999]
2009-06-25 03:58:39 -08:00
Jonathan Westhues 3da334028e Let's use the direction cosines (dot product of unit vectors), not
the arbitrary-magnitude dot product, to classify regions (inside,
outside, coincident) of surfaces against each other.

That lets me always perturb the point for the normals (inside and
outside the edge) by just a chord tolerance, and nothing bad
happens as that distance varies over a few orders of magnitude.

[git-p4: depot-paths = "//depot/solvespace/": change = 1996]
2009-06-21 22:22:30 -08:00
Jonathan Westhues bd36221219 Clean up the marching step size / chord tol stuff, and add code to
export an inexact curve by approximating it with piecwise cubic
segments (whose endpoints lie exactly on the curve, and with exact
tangent directions at the endpoints).

[git-p4: depot-paths = "//depot/solvespace/": change = 1995]
2009-06-21 18:54:09 -08:00
Jonathan Westhues 684ba7deb1 Add a menu item to rotate an imported part by ninety degrees about
the coordinate axis closest to the screen normal.

[git-p4: depot-paths = "//depot/solvespace/": change = 1994]
2009-06-21 12:39:42 -08:00
Jonathan Westhues c6a0148724 When splitting a curve against surfaces, don't split the curve
against the surfaces that it supposedly borders; that will cause
numerical trouble.

[git-p4: depot-paths = "//depot/solvespace/": change = 1993]
2009-06-21 01:54:21 -08:00
Jonathan Westhues 4c8f535305 Split line-surface intersection and shell raycasting stuff into its
own file.

[git-p4: depot-paths = "//depot/solvespace/": change = 1992]
2009-06-21 01:14:49 -08:00
Jonathan Westhues d3dcd8fb23 Now we are actually marching. There seems to be either a numerical
problem or a tendency to generate backwards edges or both, need to
debug that. But it generates the curve, and begins to work.

And change the edge classification. Now instead of testing for
point-on-surface using the results of the raycasting, test for
point-on-surface as a separate step. That stops us from picking up
the additional numerical error from the surface-line intersection,
which may be significant if the ray is parallel or almost parallel
to the surface.

[git-p4: depot-paths = "//depot/solvespace/": change = 1991]
2009-06-21 01:02:36 -08:00
Jonathan Westhues 666ea1c047 Add beginnings of marching surface intersection; I can find all the
boundary points, at least. That required some changes to what gets
passed around (for example because to project a point onto this
inexact curve, we need to know which two surfaces it trims so that
we can do a Newton's method on them).

And fix stupidity in the way that I calculated edge normals; I just
did normal in uv space, and there's no particular reason why that
would be normal in xyz. So edges in long skinny surfaces failed,
for example.

[git-p4: depot-paths = "//depot/solvespace/": change = 1990]
2009-06-18 23:56:33 -08:00
Jonathan Westhues 19fbae5b66 Oops, don't let the coincident surface merging stuff try to merge
empty (no trims) surfaces. It will generate a screwy bounding box,
which will make things break numerically later.

[git-p4: depot-paths = "//depot/solvespace/": change = 1979]
2009-06-10 00:26:09 -08:00
Jonathan Westhues 2013f9f466 Oops, was computing numerical by perturbing a point in uv; but the
xyz point that I subtracted off had been refined to lie exactly on
our edge's curve, and the uv point that I started with had not. So
normals got randomly screwed up.

[git-p4: depot-paths = "//depot/solvespace/": change = 1978]
2009-06-10 00:04:35 -08:00
Jonathan Westhues 603f47692e When exporting STEP, identify the outer contours, and group them
and their holes into their own advanced faces. So a single surface
with multiple outer contours generates multiple advanced faces.

Also turn the default chord tol down to 1.5 pixels, seems more
likely to make the exact surface Booleans work.

[git-p4: depot-paths = "//depot/solvespace/": change = 1975]
2009-06-08 08:21:33 -08:00
Jonathan Westhues 9455037e49 Add beginnings of STEP export, which weren't as horrible as I had
feared. Though I don't have rational surfaces or curves going yet,
and I don't have the stuff to handle holes or multiple outer
contours in a single surface.

[git-p4: depot-paths = "//depot/solvespace/": change = 1974]
2009-06-07 22:50:16 -08:00
Jonathan Westhues 2d653eada8 Add code to identify planes and cylindrical surfaces from a solid
of revolution, and put them in the same form as if they had been
draw by an extrusion (so that we can use all the same special case
intersection curves).

And add code to merge coincident faces into one. That turns out to
be more than a cosmetic/efficiency thing, since edge splitting
fails at the join between two coincident faces.

[git-p4: depot-paths = "//depot/solvespace/": change = 1965]
2009-06-04 21:38:41 -08:00
Jonathan Westhues ae35b3595c Revamp the edge classification for Booleans. I no longer make a
separate polygon of coincident (with same or opposite normal)
faces; I instead test all the edges against the other shell, and
have extended the classify-against-shell stuff to handle those
cases.

And the normals are now perturbed a bit numerically, to either side
of the edge, to distinguish tangency from a coincident surface.

This seems to work fairly well, although things still tend to fail
when the piecewise linear tolerance is too coarse.

[git-p4: depot-paths = "//depot/solvespace/": change = 1964]
2009-06-03 19:59:40 -08:00
Jonathan Westhues 438d517c5a If a Boolean fails, then make a note of it in the group's text
window screen, and remind the user that they could 'fix' the
problem by working with meshes instead.

[git-p4: depot-paths = "//depot/solvespace/": change = 1962]
2009-05-30 00:49:09 -08:00
Jonathan Westhues ddbd0ff77b Add ability to represent our surfaces as either a shell or a mesh,
according to the user's preference. I templated the housekeeping
stuff for Boolean operations and step and repeat, so it's
relatively clean.

Still need to add the stuff to make a mesh vertex-to-vertex, and to
export sections of a mesh.

[git-p4: depot-paths = "//depot/solvespace/": change = 1959]
2009-05-24 03:37:07 -08:00
Jonathan Westhues b4dfb1aded Add code to assemble two shells into one, without checking for any
intersections or otherwise trying to make the result not
self-intersecting.

[git-p4: depot-paths = "//depot/solvespace/": change = 1955]
2009-05-19 19:04:36 -08:00
Jonathan Westhues 1d88f96e13 Make surfaces of revolution with control points on the axis
triangulate correctly; don't screw up generating them, and make
sure that the ratpoly stuff doesn't blow up near the singularity.

[git-p4: depot-paths = "//depot/solvespace/": change = 1953]
2009-05-18 00:18:32 -08:00
Jonathan Westhues 40ed1b7ac1 Generate intersection curves for surfaces of extrusion along a
parallel axis (which are always lines parallel to that axis).

Remove short pwl segments when possible, to avoid short edges that
get misclassified.

[git-p4: depot-paths = "//depot/solvespace/": change = 1952]
2009-05-17 23:26:51 -08:00
Jonathan Westhues d6d198ee40 Add triangulation of surfaces with compound curvature; I just build
a grid of quads, with adaptive spacing. The quads that lie entirely
within the trim polygon are triangulated and knocked out from the
polygon, and then the polygon is triangulated.

That works okay, though rather slow. But there are issues with
surfaces of revolution that touch the axis, since they end up with
a singularity. That will require some thought.

[git-p4: depot-paths = "//depot/solvespace/": change = 1951]
2009-05-08 00:33:04 -08:00
Jonathan Westhues 3581d9b9ec Construct surfaces of revolution from lathe groups, although we're
not triangulating them correctly yet.

[git-p4: depot-paths = "//depot/solvespace/": change = 1950]
2009-04-28 18:42:44 -08:00
Jonathan Westhues b5c8aade21 Add exact export of arcs for EPS, DXF, SVG, and of nonrational
polynomial curves for SVG.

[git-p4: depot-paths = "//depot/solvespace/": change = 1937]
2009-04-14 18:55:18 -08:00
Jonathan Westhues 775653a75d Add beginnings of exact curve export. We take the trim curves in
our specified section plane; we then split them according to the
start and endpoints of each STrimBy, using de Castejau's algorithm.
These sections get projected (possibly in perspective, which I do
correctly) into 2d and exported.

Except, for now they just get pwl'd in the export files. That's the
fallback, since it works for any file format. But that's the place
to add special cases for circles etc., or to export them exactly.
DXF supports the latter, but very painfully since I would need to
write a later-versioned file, which requires thousands of lines of
baggage. I'll probably stick with arcs.

[git-p4: depot-paths = "//depot/solvespace/": change = 1936]
2009-04-13 20:19:23 -08:00
Jonathan Westhues 71adc0bf54 Split ratpoly.cpp; now that contains only the mathematical stuff,
and curve.cpp and surface.cpp contain the rest.

Also get rid of the meshError stuff; will just use the nakedEdges
mechanism for that. And I won't run the interference test
continuously, have added a menu item for that.

[git-p4: depot-paths = "//depot/solvespace/": change = 1934]
2009-03-28 22:05:28 -08:00
Jonathan Westhues 7f3dd91bd9 Add a special case for line-cylinder intersection, solving in
closed form. This is a fairly good speedup, and handles tangency
well.

But that shows that tangency has other problems; need to classify
edges correctly (whether they point to a coincident surface) in
curved surfaces too. I need to tweak SShell::ClassifyPoint().

[git-p4: depot-paths = "//depot/solvespace/": change = 1933]
2009-03-19 09:40:11 -08:00
Jonathan Westhues acadc0a918 Many changes:
* Rewrite surface handles in curves, so that Booleans beyond
      the first don't screw up.

    * If an intersection curve is identical to an existing curve
      (as happens when faces are coincident), take the piecewise
      linearization of the existing curve; this stops us from
      screwing up when different shells are pwl'd at different
      chord tols.

    * Hook up the plane faces again.

    * Remove coincident (parallel or anti-parallel) edges from the
      coincident-face edge lists when doing Booleans; those may
      happen if two faces are coincident with ours.

    * Miscellaneous bugfixes.

It doesn't seem to screw up very much now, although tangent edges
(and insufficient pwl resolution) may still cause problems.

[git-p4: depot-paths = "//depot/solvespace/": change = 1929]
2009-03-15 15:04:45 -08:00
Jonathan Westhues adc910185c Add plane-plane intersection as a special case (to generate the
trimmed line), and plane-line intersection. Terminate the Bezier
surface subdivision on a chord tolerance, and that seems okay now.
And print info about the graphics adapter in the text window, could
be useful.

Also have a cylinder-detection routine that works; should special
case those surfaces in closed form since they are common, but not
doing it yet.

[git-p4: depot-paths = "//depot/solvespace/": change = 1928]
2009-03-14 12:01:20 -08:00
Jonathan Westhues bc70089dd0 Add code to subdivide (with de Castljau's algorithm) a surface, and
use that for surface-line intersections. That has major problems
with the heuristic on when to stop and do Newton polishing.

There's also an issue with all the Newton stuff when surfaces join
tangent.

And update the wishlist to reflect current needs.

[git-p4: depot-paths = "//depot/solvespace/": change = 1925]
2009-03-08 02:59:57 -08:00
Jonathan Westhues 77cace05ce When clipping ears to triangulate a curved surface, clip the ear
that minimizes the chord tolerance.

[git-p4: depot-paths = "//depot/solvespace/": change = 1921]
2009-02-27 06:05:08 -08:00
Jonathan Westhues 2023667311 Add Newton iterations to intersect a line with a surface at a
point, and to intersect three surfaces at a point. So now when we
split an edge, we can refine the split point to lie exactly on the
trim curve, so I can do certain Booleans on curved surfaces.

But surface-line intersection is globally broken, since I don't
correctly detect the number of intersections or provide a good
first guess. I maybe should test by bounding boxes and subdivision.

[git-p4: depot-paths = "//depot/solvespace/": change = 1920]
2009-02-27 05:04:36 -08:00
Jonathan Westhues 3da1e1d390 Compute surface intersections in a way that is closer to what I
will do for real; now handling the special cases of plane against a
surface of extrusion. Still need to fix up line-surface
intersection to work for curved things, but then some simple curved
cases should work (as well as plane-plane).

[git-p4: depot-paths = "//depot/solvespace/": change = 1919]
2009-02-23 02:06:02 -08:00
Jonathan Westhues 9ade574d36 Fix triangulation issues when a polygon has more than two edges at
a vertex.

[git-p4: depot-paths = "//depot/solvespace/": change = 1916]
2009-02-18 03:15:33 -08:00
Jonathan Westhues 577cdf2255 More coincident fixing; test for edge-on-edge, fix some gross
stupidity.

[git-p4: depot-paths = "//depot/solvespace/": change = 1915]
2009-02-17 03:17:12 -08:00
Jonathan Westhues c6b429b9ce Additional poking at Booleans. At least this is a halfway rational
way to think about the cases; I'm classifying the regions to the
left and right of each edge, and keeping the edges if those regions
(2d, surfaces) classify different.

Still screws up with edge-on-edge intersections; but if I make the
surface intersection stuff handle that, then might be more
straightforward to use that info.

[git-p4: depot-paths = "//depot/solvespace/": change = 1914]
2009-02-16 04:05:08 -08:00
Jonathan Westhues 90842131ff Make Boolean union work when the shells have coincident plane
faces. Still on planes only, no curved surface intersections.

[git-p4: depot-paths = "//depot/solvespace/": change = 1912]
2009-02-09 04:40:48 -08:00
Jonathan Westhues d0ab8270d9 Fix stupidity in Point2d::DistanceToLine, and classify line
segments in Boolean against the shell, not the intersection
polygon. (We just cast a ray, and use the surface-line intersection
function that already existed.) That's slow, but can be
accelerated later.

[git-p4: depot-paths = "//depot/solvespace/": change = 1911]
2009-02-01 05:01:28 -08:00
Jonathan Westhues 9ffe95ea65 More work on Booleans. This works only for planes, and only for
non-coincident faces. There's also a problem when I don't generate
the full intersection polygon of shell B against a given surface in
shell A; I need to modify the code to not require that.

[git-p4: depot-paths = "//depot/solvespace/": change = 1910]
2009-01-31 21:13:43 -08:00
Jonathan Westhues 715a554637 So that's why projection into the surface kept failing; was using
the magnitude of the wrong derivative! Fix that, good.

[git-p4: depot-paths = "//depot/solvespace/": change = 1908]
2009-01-27 01:22:18 -08:00
Jonathan Westhues a754018a44 More poking at Booleans; generate the unsplit intersection curves
for planes against planes.

[git-p4: depot-paths = "//depot/solvespace/": change = 1907]
2009-01-26 23:59:58 -08:00
Jonathan Westhues 95bded27ee Add eps, hpgl, and svg output (simple, all just for polylines). And
fix convergence tolerance so that points projected into a rational
polynomial surface end up much closer than LENGTH_EPS.

[git-p4: depot-paths = "//depot/solvespace/": change = 1906]
2009-01-26 21:48:40 -08:00
Jonathan Westhues 07ddd62a3a Preparatory work for Boolean. Make the u and v coordinates of the
trim curves for all surfaces lie between 0 and 1. And add routines
to merge the curves and surfaces from two shells into one, and to
split the trim curves into their piecewise linear segments and then
reassemble them into trim curves.

[git-p4: depot-paths = "//depot/solvespace/": change = 1905]
2009-01-25 03:52:29 -08:00
Jonathan Westhues 2e4ec6dd04 Add sin and cos to the expression entry (for dimensions etc.), with
the same precedence as sqrt. Add the code to find naked edges, and
draw them highlighted on the model. And make the direction of trim
curves consistent, always ccw with normal toward viewer; so there's
no need to fix the directions before triangulating.

[git-p4: depot-paths = "//depot/solvespace/": change = 1903]
2009-01-25 01:19:59 -08:00
Jonathan Westhues bb4b767e99 Tear everything apart, moving away from meshes and toward shells.
Add stubs for functions to perform Booleans, and get rid of mesh
stuff, including the kd tree accelerated snap to vertex (which
should not be required if the shell triangulation performs as it
should).

Also check that a sketch is not self-intersecting before extruding
it or whatever. This is dead slow, needs n*log(n) implementation.

[git-p4: depot-paths = "//depot/solvespace/": change = 1902]
2009-01-22 19:30:30 -08:00
Jonathan Westhues 6d7954e167 Fix an issue with edge intersection testing: if a vertex from edge
A touches edge B, but does not share a vertex with edge B, then
that's an intersection.

Adjust the ear clipping so that it generates strip-like
triangulations, not fan-like.

And rearrange deck chairs on the bridge-finding code, which is
still pathetically slow. It may not be possible to get reasonable
performance without kd tree type acceleration.

[git-p4: depot-paths = "//depot/solvespace/": change = 1901]
2009-01-22 02:02:46 -08:00
Jonathan Westhues 7cf3a06274 A very rough set of routines to triangulate by ear clipping. This
is O(n^2), not perfectly robust, and the bridge-finding code is
particularly bad. But it works, triangulates, and shouldn't ever
generate zero-area triangles like gl does.

[git-p4: depot-paths = "//depot/solvespace/": change = 1900]
2009-01-20 21:04:38 -08:00
Jonathan Westhues ebca6130ec Early attempts at rational polynomial surfaces. I can create one
from an extrusion, with piecewise linear trim curves for everything
(that are shared, so that they appear only once for the two
surfaces that each trims). No Boolean operations on them, and the
triangulation is bad, because gl seems to merge collinear edges.

So before going further, I seem to need my own triangulation code.
I have not had great luck in the past, but I can't live without it
now.

[git-p4: depot-paths = "//depot/solvespace/": change = 1899]
2009-01-19 02:37:10 -08:00