@@ -45,6 +45,9 @@ export default class NyquistPlot {
4545
4646 #nyquistObserver;
4747
48+ //plot colors
49+ #curveSegmentColor1 = "#4682b4" ;
50+ #curveSegmentColor2 = "#aaaaaa" ;
4851 constructor (
4952 plotContainerDomElement ,
5053 numeratorTermsArray ,
@@ -156,8 +159,6 @@ export default class NyquistPlot {
156159 }
157160
158161 createNyquistPlot ( ) {
159- const arrowsNumber = 100 ;
160-
161162 let plotBoundRect = this . #nyquistPlotDomElement. getBoundingClientRect ( ) ;
162163 let plotWidth = plotBoundRect . width ;
163164 let plotHeight = plotBoundRect . height ;
@@ -171,6 +172,9 @@ export default class NyquistPlot {
171172 // const minImag = Math.min(...imags);
172173 // const maxImag = Math.max(...imags);
173174
175+ const arrowsNumber = 100 ;
176+ const maxAllowedDistanceOfConsecutivePoints = 50 ;
177+
174178 //set limits for coordinates of plotted points
175179 const xMax = 10 ** 4 ;
176180 const yMax = 10 ** 4 ;
@@ -198,31 +202,41 @@ export default class NyquistPlot {
198202 // )(scope.x);
199203 // },
200204 // },
201- {
202- points : this . #curvePoints
203- . filter ( ( x ) => x [ 0 ] > 0 && x [ 1 ] < xMax && x [ 2 ] < yMax )
204- . map ( ( x ) => [ x [ 1 ] , x [ 2 ] ] ) ,
205- // color: "red",
206- fnType : "points" ,
207- graphType : "polyline" ,
208- } ,
209- {
210- points : this . #curvePoints
211- . filter ( ( x ) => x [ 0 ] < 0 && x [ 1 ] > - xMax && x [ 2 ] > - yMax )
212- . map ( ( x ) => [ x [ 1 ] , x [ 2 ] ] ) ,
213- fnType : "points" ,
214- graphType : "polyline" ,
215- color : "gray" ,
216- } ,
217205 // {
218206 // graphType: "polyline",
219- // color: "gray",
220207 // fn: (scope) => {
221208 // return linearInterpolationOfCurvePoints(
222209 // this.#curvePoints.filter((x) => x[0] < 0).map((x) => [x[1], x[2]])
223210 // )(scope.x);
224211 // },
212+ // color: this.#curveSegmentColor2,
225213 // },
214+ ...divideNyquistCurveIntoSegments (
215+ this . #curvePoints
216+ . filter ( ( x ) => x [ 0 ] > 0 && x [ 1 ] < xMax && x [ 2 ] < yMax )
217+ . map ( ( x ) => [ x [ 1 ] , x [ 2 ] ] ) ,
218+ maxAllowedDistanceOfConsecutivePoints
219+ ) . map ( ( curvePointsSegment ) => {
220+ return {
221+ points : curvePointsSegment ,
222+ fnType : "points" ,
223+ graphType : "polyline" ,
224+ color : this . #curveSegmentColor1,
225+ } ;
226+ } ) ,
227+ ...divideNyquistCurveIntoSegments (
228+ this . #curvePoints
229+ . filter ( ( x ) => x [ 0 ] < 0 && x [ 1 ] > - xMax && x [ 2 ] > - yMax )
230+ . map ( ( x ) => [ x [ 1 ] , x [ 2 ] ] ) ,
231+ maxAllowedDistanceOfConsecutivePoints
232+ ) . map ( ( curvePointsSegment ) => {
233+ return {
234+ points : curvePointsSegment ,
235+ fnType : "points" ,
236+ graphType : "polyline" ,
237+ color : this . #curveSegmentColor2,
238+ } ;
239+ } ) ,
226240 {
227241 points : this . #zeros,
228242 fnType : "points" ,
@@ -409,7 +423,7 @@ const computeNyquistRealAndImagWFunctions = function (
409423 ) ;
410424
411425 //
412- // define magnitude & phase functions
426+ // define real & imag functions
413427 //
414428 const numReal = functionFromPolynomialTermsArray (
415429 polynomialEvaluatedWithWiRealTermsArray ( numeratorTermsArray )
@@ -467,3 +481,41 @@ const computeStability = function (numeratorTermsArray, denominatorTermsArray) {
467481 }
468482 return stability ;
469483} ;
484+
485+ /**
486+ * Divide a Nyquist plot curve into multiple segments, in case
487+ * connections between two consecutive points of paths tending into inf
488+ * are expected to be made
489+ *
490+ * @returns an array of curve segments
491+ * (with each curve segment as an array of points)
492+ */
493+ const divideNyquistCurveIntoSegments = (
494+ curvePoints ,
495+ maxAllowedDistanceOfConsecutivePoints
496+ ) => {
497+ const allSegments = [ ] ;
498+ let currentSegment = [ ] ;
499+
500+ for ( let p of curvePoints ) {
501+ if ( currentSegment . length === 0 ) {
502+ currentSegment . push ( p ) ;
503+ } else {
504+ const lastP = currentSegment . slice ( - 1 ) [ 0 ] ;
505+
506+ if (
507+ ( lastP [ 0 ] * p [ 0 ] < 0 || lastP [ 1 ] * p [ 1 ] < 0 ) &&
508+ Math . sqrt ( ( lastP [ 0 ] - p [ 0 ] ) ** 2 + ( lastP [ 1 ] - p [ 1 ] ) ** 2 ) >
509+ maxAllowedDistanceOfConsecutivePoints
510+ ) {
511+ //segment end
512+ allSegments . push ( [ ...currentSegment ] ) ;
513+ currentSegment = [ ] ;
514+ }
515+ currentSegment . push ( p ) ;
516+ }
517+ }
518+ allSegments . push ( [ ...currentSegment ] ) ;
519+
520+ return allSegments ;
521+ } ;
0 commit comments