menno
(Menno Deij - van Rijswijk)
July 17, 2013, 6:35am
1
FYI, I see sometimes that the code in the post referenced below is truncated and the last 5-10 lines are not visible. Is this a problem with Discourse?
Continuing the discussion from Surface.ClosestPoint() gives large deviations where none should exist :
If I create a surface using the code below and evaluate points on the surface’s boundary curves, I expected that the points that are found on the surface are within zero tolerance to the point on the boundary curve. The output of the code below, however, paints a different picture, where deviations up to 0.23 are found.
The problem is quite sensitive to 1) the location of the initial points and 2) the choice of knot style. But, even so, for a relatively simple surface like the one in the example, I don’t expect such large deviations.
output:
large distance! 0.0185262564697653
large distance! 0.233779029389498
large distance! 0.23783011958997
large distance! 0.0503318751917803
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Point3dList nort = new Point3dList(
new Point3d( 0, 0, 0),
new Point3d( 1, 0, 0),
new Point3d( 2, 0, 0),
new Point3d( 3, 0, 0),
new Point3d(10, 0, 0)
);
Transform rotate90 = Transform.Rotation(Math.PI/2, new Point3d(5,5,0));
Point3dList west = new Point3dList(nort);
west.Transform(rotate90);
Point3dList sout = new Point3dList(west);
sout.Transform(rotate90);
Point3dList east = new Point3dList(sout);
east.Transform(rotate90);
NurbsCurve cnort = Curve.CreateInterpolatedCurve(nort, 3, CurveKnotStyle.Uniform).ToNurbsCurve();
NurbsCurve cwest = Curve.CreateInterpolatedCurve(west, 3, CurveKnotStyle.Uniform).ToNurbsCurve();
NurbsCurve csout = Curve.CreateInterpolatedCurve(sout, 3, CurveKnotStyle.Uniform).ToNurbsCurve();
NurbsCurve ceast = Curve.CreateInterpolatedCurve(east, 3, CurveKnotStyle.Uniform).ToNurbsCurve();
Brep b = Brep.CreateEdgeSurface(new[] {cnort, cwest, csout, ceast});
NurbsSurface s = b.Surfaces[0].ToNurbsSurface();
Test(s, cnort, doc);
Test(s, cwest, doc);
Test(s, csout, doc);
Test(s, ceast, doc);
doc.Objects.Add(b);
return Result.Success;
}
private void Test(NurbsSurface s, NurbsCurve curve, RhinoDoc doc)
{
foreach (double t in Range(curve.Domain, 100))
{
Point3d pt = curve.PointAt(t);
double u, v;
if (s.ClosestPoint(pt, out u, out v))
{
Point3d onSrf = s.PointAt(u, v);
if (onSrf.DistanceTo(pt) > RhinoMath.ZeroTolerance)
{
RhinoApp.WriteLine("large distance! "+onSrf.DistanceTo(pt).ToString("g"));
doc.Objects.AddLine(pt, onSrf);
}
}
}
}
private IEnumerable Range(Interval interval, int nSteps)
{
yield return interval.T0;
double step = interval.Length/nSteps;
for (int i = 0; i < nSteps - 1; ++i)
yield return interval.T0 + i*step;
yield return interval.T1;
}
menno
(Menno Deij - van Rijswijk)
July 17, 2013, 6:36am
2
Ok, in this topic it shows correctly. The original topic has the truncated code.
sam
July 17, 2013, 9:15am
3
Yeah … we fixed the bug a while back, we just upgraded mcneel earlier this week.
menno
(Menno Deij - van Rijswijk)
July 17, 2013, 9:57am
4
The original topic to which this topic is a continuation was posted 20h ago. The upgrade was performed since then?
When I was posting the original topic, I first saw that it was wrong, I posted the last bit in a second entry. Then all of a sudden it looked OK again, so I removed the second entry. But, when I looked today, the code was again truncated.
You sure it was really fixed?
sam
July 17, 2013, 10:55am
5
hmmm I wonder if I am confusing this with a different bug…
any chance you can reproduce this on http://try.discourse.org/ , if you can give me a clear repro I will be sure to sort it asap
menno
(Menno Deij - van Rijswijk)
July 17, 2013, 11:09am
6
@sam see try.discourse.org/t/testing-testing-123/133
it has the same problem - i just pasted the text from the original topic verbatim to try.discourse.org
sam
July 17, 2013, 12:31pm
7
aha … looks like invalid markup … you have <pre>abc<code></code></pre>
I suspect its tripping our parser… in general I strongly recommend using github style code blocks, they give you lovely syntax highlighting eg:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Point3dList nort = new Point3dList(
new Point3d( 0, 0, 0),
new Point3d( 1, 0, 0),
new Point3d( 2, 0, 0),
new Point3d( 3, 0, 0),
new Point3d(10, 0, 0)
);
```
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Point3dList nort = new Point3dList(
new Point3d( 0, 0, 0),
new Point3d( 1, 0, 0),
new Point3d( 2, 0, 0),
new Point3d( 3, 0, 0),
new Point3d(10, 0, 0)
);
```
menno
(Menno Deij - van Rijswijk)
July 17, 2013, 12:58pm
8
Ok, my bad. I’ll use the Github style. Thanks for clearing that up