Skip to content

Commit c4f3048

Browse files
committed
First Successful Test Build
1 parent 1a9e7c9 commit c4f3048

7 files changed

+1013
-4
lines changed

LineLineAnalyticalIntersection2d.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rhino;
7+
using Rhino.Geometry;
8+
using Rhino.Collections;
9+
10+
namespace QuadHyp
11+
{
12+
public class LineLineAnalyticalIntersection2d
13+
{
14+
public Line line1;
15+
public Line line2;
16+
public double t1;
17+
public double t2;
18+
public bool isIntersecting;
19+
public bool isAtEnds = false;
20+
public Point3d intersectionPoint;
21+
22+
double p0, p1, p2, p3;
23+
double x0, x1, x2, x3;
24+
double y0, y1, y2, y3;
25+
26+
public LineLineAnalyticalIntersection2d(Line _line1, Line _line2)
27+
{
28+
line1 = _line1;
29+
line2 = _line2;
30+
x0 = line1.From.X;
31+
x1 = line1.To.X;
32+
x2 = line2.From.X;
33+
x3 = line2.To.X;
34+
35+
y0 = line1.From.Y;
36+
y1 = line1.To.Y;
37+
y2 = line2.From.Y;
38+
y3 = line2.To.Y;
39+
40+
CalculateIntersection();
41+
42+
}
43+
44+
void CalculateIntersection()
45+
{
46+
p0 = (y3 - y2) * (x3 - x0) - (x3 - x2) * (y3 - y0);
47+
p1 = (y3 - y2) * (x3 - x1) - (x3 - x2) * (y3 - y1);
48+
p2 = (y1 - y0) * (x1 - x2) - (x1 - x0) * (y1 - y2);
49+
p3 = (y1 - y0) * (x1 - x3) - (x1 - x0) * (y1 - y3);
50+
isIntersecting = ((p0 * p1) <= 0) & ((p2 * p3) <= 0);
51+
if (isIntersecting)
52+
{
53+
double det;
54+
det = (x1 - x0) * (y3 - y2) - (y1 - y0) * (x3 - x2);
55+
t1 = 1 / det * (
56+
(y3 - y2) * (x2 - x0) - (x3 - x2) * (y2 - y0)
57+
);
58+
t2 = 1 / det * (
59+
(y1 - y0) * (x2 - x0) - (x1 - x0) * (y2 - y0)
60+
);
61+
intersectionPoint = line1.PointAt(t1);
62+
}
63+
if ((((t1 == 0) ? 1 : 0) + ((t2 == 0) ? 1 : 0) + ((t1 == 1) ? 1 : 0) + ((t2 == 1) ? 1 : 0)) >= 1)
64+
{
65+
isAtEnds = true;
66+
}
67+
}
68+
69+
70+
71+
72+
}
73+
}
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rhino;
7+
using Rhino.Geometry;
8+
using Rhino.Collections;
9+
10+
namespace QuadHyp
11+
{
12+
public class PolygonPolygonAnalyticalIntersection2d
13+
{
14+
public NurbsCurve testCurve;
15+
public NurbsCurve trimCurve;
16+
public List<double> tsTest = new List<double>();
17+
public List<double> tsTrim = new List<double>();
18+
public List<IntersectionPointRelation> relations = new List<IntersectionPointRelation>();
19+
public List<Point3d> intersectionPoints = new List<Point3d>();
20+
public bool hasResult = false;
21+
22+
23+
int testCurveSpanCount;
24+
List<Interval> testCurveDomains = new List<Interval>();
25+
List<double> testCurveTurningTs = new List<double>();
26+
List<Line> testCurveSegments = new List<Line>();
27+
28+
public List<Span> testSpans = new List<Span>();
29+
30+
31+
int trimCurveSpanCount;
32+
List<Interval> trimCurveDomains = new List<Interval>();
33+
List<double> trimCurveTurningTs = new List<double>();
34+
List<Line> trimCurveSegments = new List<Line>();
35+
36+
public List<Span> trimSpans = new List<Span>();
37+
38+
public List<Span> resultSpans = new List<Span>();
39+
public List<NurbsCurve> resultCurves = new List<NurbsCurve>();
40+
41+
public NurbsCurve resultCurve;
42+
43+
44+
public PolygonPolygonAnalyticalIntersection2d(NurbsCurve _testCurve, NurbsCurve _trimCurve)
45+
{
46+
testCurve = _testCurve;
47+
trimCurve = _trimCurve;
48+
49+
testCurveSpanCount = testCurve.SpanCount;
50+
for (int i = 0; i < testCurveSpanCount; i++)
51+
{
52+
testCurveDomains.Add(testCurve.SpanDomain(i));
53+
testCurveSegments.Add(new Line(testCurve.PointAt(testCurve.SpanDomain(i).T0), testCurve.PointAt(testCurve.SpanDomain(i).T1)));
54+
testCurveTurningTs.Add(testCurve.SpanDomain(i).T0);
55+
}
56+
testCurveTurningTs.Add(testCurve.SpanDomain(testCurve.SpanCount - 1).T1);
57+
58+
trimCurveSpanCount = trimCurve.SpanCount;
59+
for (int i = 0; i < trimCurveSpanCount; i++)
60+
{
61+
trimCurveDomains.Add(trimCurve.SpanDomain(i));
62+
trimCurveSegments.Add(new Line(trimCurve.PointAt(trimCurve.SpanDomain(i).T0), trimCurve.PointAt(trimCurve.SpanDomain(i).T1)));
63+
trimCurveTurningTs.Add(trimCurve.SpanDomain(i).T0);
64+
}
65+
trimCurveTurningTs.Add(trimCurve.SpanDomain(trimCurve.SpanCount - 1).T1);
66+
67+
CalculateIntersections();
68+
69+
}
70+
71+
public PolygonPolygonAnalyticalIntersection2d(NurbsCurve _testCurve, NurbsCurve _trimCurve, bool coarse)
72+
{
73+
testCurve = _testCurve;
74+
trimCurve = _trimCurve;
75+
76+
testCurveSpanCount = testCurve.SpanCount;
77+
for (int i = 0; i < testCurveSpanCount; i++)
78+
{
79+
testCurveDomains.Add(testCurve.SpanDomain(i));
80+
testCurveSegments.Add(new Line(testCurve.PointAt(testCurve.SpanDomain(i).T0), testCurve.PointAt(testCurve.SpanDomain(i).T1)));
81+
testCurveTurningTs.Add(testCurve.SpanDomain(i).T0);
82+
}
83+
testCurveTurningTs.Add(testCurve.SpanDomain(testCurve.SpanCount - 1).T1);
84+
85+
trimCurveSpanCount = trimCurve.SpanCount;
86+
for (int i = 0; i < trimCurveSpanCount; i++)
87+
{
88+
trimCurveDomains.Add(trimCurve.SpanDomain(i));
89+
trimCurveSegments.Add(new Line(trimCurve.PointAt(trimCurve.SpanDomain(i).T0), trimCurve.PointAt(trimCurve.SpanDomain(i).T1)));
90+
trimCurveTurningTs.Add(trimCurve.SpanDomain(i).T0);
91+
}
92+
trimCurveTurningTs.Add(trimCurve.SpanDomain(trimCurve.SpanCount - 1).T1);
93+
94+
if (coarse)
95+
{
96+
int numInside = 0;
97+
foreach (double t in testCurveTurningTs)
98+
{
99+
if (PointInsidePolygon2d(trimCurve, testCurve.PointAt(t)) != PointContainment.Outside)
100+
{
101+
numInside++;
102+
}
103+
}
104+
if (numInside == testCurveTurningTs.Count)
105+
{
106+
resultCurves.Add(testCurve);
107+
resultCurve = testCurve;
108+
hasResult = true;
109+
return;
110+
}
111+
}
112+
CalculateIntersections();
113+
}
114+
115+
116+
public PointContainment PointInsidePolygon2d(NurbsCurve targetCurve, Point3d testPoint)
117+
{
118+
PointContainment contains = targetCurve.Contains(testPoint, Plane.WorldXY, 0.001);
119+
return contains;
120+
}
121+
122+
void sortAndRemoveDuplicates(List<double> list)
123+
{
124+
list.Sort();
125+
int i = 0;
126+
while (i < list.Count - 1)
127+
{
128+
if (list[i] == list[i + 1])
129+
{
130+
list.RemoveAt(i);
131+
}
132+
else
133+
{
134+
i++;
135+
}
136+
}
137+
}
138+
139+
void CalculateIntersections()
140+
{
141+
LineLineAnalyticalIntersection2d LLI2;
142+
List<double> intersectionTestCurveTs = new List<double>();
143+
List<double> intersectionTrimCurveTs = new List<double>();
144+
List<Point3d> ttpt = new List<Point3d>();
145+
146+
for (int iTest = 0; iTest < testCurve.SpanCount; iTest++)
147+
{
148+
149+
for (int iTrim = 0; iTrim < trimCurve.SpanCount; iTrim++)
150+
{
151+
LLI2 = new LineLineAnalyticalIntersection2d(testCurveSegments[iTest], trimCurveSegments[iTrim]);
152+
if (LLI2.isIntersecting)
153+
{
154+
intersectionTestCurveTs.Add(LLI2.t1 * (-testCurveDomains[iTest].T0 + testCurveDomains[iTest].T1) + testCurveDomains[iTest].T0);
155+
intersectionTrimCurveTs.Add(LLI2.t2 * (-trimCurveDomains[iTrim].T0 + trimCurveDomains[iTrim].T1) + trimCurveDomains[iTrim].T0);
156+
}
157+
}
158+
}
159+
160+
intersectionTestCurveTs.AddRange(testCurveTurningTs);
161+
sortAndRemoveDuplicates(intersectionTestCurveTs);
162+
163+
intersectionTrimCurveTs.AddRange(trimCurveTurningTs);
164+
sortAndRemoveDuplicates(intersectionTrimCurveTs);
165+
166+
Span span;
167+
for (int iTest = 0; iTest < intersectionTestCurveTs.Count - 1; iTest++)
168+
{
169+
span = new Span(testCurve, new Interval(intersectionTestCurveTs[iTest], intersectionTestCurveTs[iTest + 1]));
170+
span.ConfigureRelations(trimCurve);
171+
testSpans.Add(span);
172+
}
173+
174+
for (int iTrim = 0; iTrim < intersectionTrimCurveTs.Count - 1; iTrim++)
175+
{
176+
span = new Span(trimCurve, new Interval(intersectionTrimCurveTs[iTrim], intersectionTrimCurveTs[iTrim + 1]));
177+
span.ConfigureRelations(testCurve);
178+
trimSpans.Add(span);
179+
}
180+
181+
resultSpans.AddRange(testSpans.FindAll(x => !(x.spanRelation.Equals(SpanRelation.Outside))));
182+
resultSpans.AddRange(trimSpans.FindAll(x => !(x.spanRelation.Equals(SpanRelation.Outside))));
183+
184+
if ((resultSpans.Count != 0) & (resultSpans != null))
185+
{
186+
Console.WriteLine("123");//TODO
187+
188+
foreach (Span s in resultSpans)
189+
{
190+
resultCurves.Add(s.line.ToNurbsCurve());
191+
}
192+
resultCurve = Curve.JoinCurves(resultCurves)[0].ToNurbsCurve();
193+
hasResult = true;
194+
}
195+
else
196+
{
197+
hasResult = false;
198+
}
199+
200+
}
201+
202+
}
203+
204+
}

QuadHyp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@
5656
</Reference>
5757
</ItemGroup>
5858
<ItemGroup>
59+
<Compile Include="LineLineAnalyticalIntersection2d.cs" />
60+
<Compile Include="PolygonPolygonAnalyticalIntersection2d.cs" />
5961
<Compile Include="QuadHypComponent.cs" />
6062
<Compile Include="QuadHypInfo.cs" />
6163
<Compile Include="Properties\AssemblyInfo.cs" />
64+
<Compile Include="Span.cs" />
65+
<Compile Include="SurfaceQuadSubdivision.cs" />
6266
</ItemGroup>
6367
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6468
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

0 commit comments

Comments
 (0)