Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: solvespace/solvespace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 83b0402c845f
Choose a base ref
...
head repository: solvespace/solvespace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f7b6f6930e06
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Mar 27, 2020

  1. Nurbs (#473)

    * Limit u,v range between 0 and 1 in Newton. Fixes issue #471
    * Change the math for projecting a point onto a plane to work better with non-orthogonal U,V derivatives in several places. Fixes #472.
    phkahler authored Mar 27, 2020
    Copy the full SHA
    f7b6f69 View commit details
Showing with 46 additions and 16 deletions.
  1. +46 −16 src/srf/ratpoly.cpp
62 changes: 46 additions & 16 deletions src/srf/ratpoly.cpp
Original file line number Diff line number Diff line change
@@ -439,9 +439,14 @@ void SSurface::ClosestPointTo(Vector p, double *u, double *v, bool mustConverge)
bu = (ctrl[1][0]).Minus(orig),
bv = (ctrl[0][1]).Minus(orig);
if((ctrl[1][1]).Equals(orig.Plus(bu).Plus(bv))) {

Vector n = bu.Cross(bv);
Vector ty = n.Cross(bu).ScaledBy(1.0/bu.MagSquared());
Vector tx = bv.Cross(n).ScaledBy(1.0/bv.MagSquared());

Vector dp = p.Minus(orig);
*u = dp.Dot(bu) / bu.MagSquared();
*v = dp.Dot(bv) / bv.MagSquared();
*u = dp.Dot(bu) / tx.MagSquared();
*v = dp.Dot(bv) / ty.MagSquared();
return;
}
}
@@ -501,16 +506,28 @@ bool SSurface::ClosestPointNewton(Vector p, double *u, double *v, bool mustConve
}
}

Vector tu, tv;
Vector tu, tv, tx, ty;
TangentsAt(*u, *v, &tu, &tv);
Vector n = tu.Cross(tv);
// since tu and tv may not be orthogonal, use y in place of v.
// |y| = |v|sin(theta) where theta is the angle between tu and tv.
ty = n.Cross(tu).ScaledBy(1.0/tu.MagSquared());
tx = tv.Cross(n).ScaledBy(1.0/tv.MagSquared());

// Project the point into a plane through p0, with basis tu, tv; a
// second-order thing would converge faster but needs second
// derivatives.
Vector dp = p.Minus(p0);
double du = dp.Dot(tu), dv = dp.Dot(tv);
*u += du / (tu.MagSquared());
*v += dv / (tv.MagSquared());
double du = dp.Dot(tx),
dv = dp.Dot(ty);
*u += du / (tx.MagSquared());
*v += dv / (ty.MagSquared());

if (*u < 0.0) *u = 0.0;
else if (*u > 1.0) *u = 1.0;
if (*v < 0.0) *v = 0.0;
else if (*v > 1.0) *v = 1.0;

}

if(mustConverge) {
@@ -540,13 +557,17 @@ bool SSurface::PointIntersectingLine(Vector p0, Vector p1, double *u, double *v)
// Check for convergence
if(pi.Equals(p, RATPOLY_EPS)) return true;

n = tu.Cross(tv);
Vector ty = n.Cross(tu).ScaledBy(1.0/tu.MagSquared());
Vector tx = tv.Cross(n).ScaledBy(1.0/tv.MagSquared());

// Adjust our guess and iterate
Vector dp = pi.Minus(p);
double du = dp.Dot(tu), dv = dp.Dot(tv);
*u += du / (tu.MagSquared());
*v += dv / (tv.MagSquared());
double du = dp.Dot(tx), dv = dp.Dot(ty);
*u += du / tx.MagSquared();
*v += dv / ty.MagSquared();
}
// dbp("didn't converge (surface intersecting line)");
dbp("didn't converge (surface intersecting line)");
return false;
}

@@ -582,10 +603,14 @@ Vector SSurface::ClosestPointOnThisAndSurface(SSurface *srf2, Vector p) {

// Adjust our guess and iterate
for(j = 0; j < 2; j++) {
Vector n = tu[j].Cross(tv[j]);
Vector ty = n.Cross(tu[j]).ScaledBy(1.0/tu[j].MagSquared());
Vector tx = tv[j].Cross(n).ScaledBy(1.0/tv[j].MagSquared());

Vector dc = pc.Minus(cp[j]);
double du = dc.Dot(tu[j]), dv = dc.Dot(tv[j]);
puv[j].x += du / ((tu[j]).MagSquared());
puv[j].y += dv / ((tv[j]).MagSquared());
double du = dc.Dot(tx), dv = dc.Dot(ty);
puv[j].x += du / tx.MagSquared();
puv[j].y += dv / ty.MagSquared();
}
}
if(i >= 10) {
@@ -637,10 +662,15 @@ void SSurface::PointOnSurfaces(SSurface *s1, SSurface *s2, double *up, double *v
if(parallel) break;

for(j = 0; j < 3; j++) {
Vector n = tu[j].Cross(tv[j]);
Vector ty = n.Cross(tu[j]).ScaledBy(1.0/tu[j].MagSquared());
Vector tx = tv[j].Cross(n).ScaledBy(1.0/tv[j].MagSquared());

Vector dp = pi.Minus(p[j]);
double du = dp.Dot(tu[j]), dv = dp.Dot(tv[j]);
u[j] += du / (tu[j]).MagSquared();
v[j] += dv / (tv[j]).MagSquared();
double du = dp.Dot(tx), dv = dp.Dot(ty);

u[j] += du / tx.MagSquared();
v[j] += dv / ty.MagSquared();
}
}
dbp("didn't converge (three surfaces intersecting)");