Skip to content

Commit bc05e33

Browse files
committed
Improve/fix densification of segments going through pole.
1 parent 2632ade commit bc05e33

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

Visual_Studio_2015/GraphicalDebugging/Geometry.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,14 @@ public static Point[] SphericalDensify(Point p0, Point p1, double length, Unit u
784784
++n;
785785

786786
Point axis;
787-
double pi = HalfAngle(unit);
788-
if (!Equals(angle01, pi))
787+
if (!Equals(angle01, Math.PI))
789788
{
790789
axis = Cross(xyz0, xyz1);
791790
VecNormalize(axis);
792791
}
793792
else
794793
{
795-
double halfPi = pi / 2;
794+
double halfPi = HalfAngle(unit) / 2;
796795
if (Equals(p0[1], halfPi))
797796
axis = new Point(0, 1, 0);
798797
else if (Equals(p0[1], -halfPi))

Visual_Studio_2015/GraphicalDebugging/Viewport.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,53 @@ private static PointF Translated(PointF p, float translation_x)
357357

358358
private static PointF[] DensifyAndConvert(LocalCS cs, Geometry.Point p0, Geometry.Point p1, double length, Geometry.Unit unit)
359359
{
360+
double distNorm = Geometry.NormalizedAngleSigned(p1[0] - p0[0], unit);
361+
bool intersPole = IsAntipodal(distNorm, unit);
362+
double halfPi = Geometry.HalfAngle(unit) / 2;
363+
double poleLat = p1[1] - p0[1] >= 0 ? halfPi : -halfPi;
364+
int intersPoleIndex = -1;
365+
360366
Geometry.Point[] densPoints = Geometry.SphericalDensify(p0, p1, length, unit);
361-
PointF[] result = new PointF[densPoints.Length];
362-
for (int j = 0; j < densPoints.Length; ++j)
367+
PointF[] result = new PointF[densPoints.Length + (intersPole ? 2 : 0)];
368+
int k = 0;
369+
for (int j = 0; j < densPoints.Length; ++j, ++k)
363370
{
364371
double densDistNorm = Geometry.NormalizedAngleSigned(densPoints[j][0] - p0[0], unit);
365372
densPoints[j][0] = p0[0] + densDistNorm;
366-
result[j] = cs.Convert(densPoints[j]);
373+
374+
if (intersPole
375+
&& intersPoleIndex == -1
376+
&& Math.Abs(densDistNorm) > halfPi)
377+
{
378+
intersPoleIndex = j;
379+
Geometry.Point p = j == 0 ? p0 : densPoints[j - 1];
380+
float poleF = cs.ConvertY(poleLat);
381+
result[k++] = new PointF(cs.ConvertX(p[0]), poleF);
382+
result[k++] = new PointF(cs.ConvertX(densPoints[j][0]), poleF);
383+
}
384+
385+
result[k] = cs.Convert(densPoints[j]);
367386
}
387+
388+
// last segment
389+
if (intersPole && intersPoleIndex == -1)
390+
{
391+
int j = densPoints.Length;
392+
intersPoleIndex = j;
393+
float poleF = cs.ConvertY(poleLat);
394+
result[j] = new PointF(cs.ConvertX(densPoints[j - 1][0]), poleF);
395+
result[j + 1] = new PointF(cs.ConvertX(p1[0]), poleF);
396+
}
397+
368398
return result;
369399
}
370400

401+
public static bool IsAntipodal(double distNorm, Geometry.Unit unit)
402+
{
403+
double pi = Geometry.HalfAngle(unit);
404+
return Math.Abs(Math.Abs(distNorm) - pi) < double.Epsilon * pi;
405+
}
406+
371407
// NOTE: This method assumes that the geometry is closed
372408
// It's suitable only for areal geometries
373409
public PointF[] AreaPointsF(Drawer drawer, float translation_x)

0 commit comments

Comments
 (0)