public bool extendToInfinite( Line2 other ) { double[] constants = new double[ 2 ]; Vec2 result = new Vec2( 0, 0 ); if( intersectInfiniteInternal( other, ref result, ref constants ) == false ) return false; if( constants[ 0 ] > 1 ) { init( v1, result ); return true; } if( constants[ 0 ] < 0 ) { init( result, v2 ); return true; } return false; }
void DrawPickupBobbin( Drawer d, Line2 centreLine, double dStringSpacing, double dWidth ) { // polepiece positions Vec2 vStartSpot = ( centreLine.v1 + centreLine.v2 ) * 0.5 - centreLine.direction * ( m_iStringCount - 1 ) * 0.5 * dStringSpacing; Vec2 vEndSpot = vStartSpot + centreLine.direction * dStringSpacing * ( m_iStringCount - 1 ); Line2 trueCentreLine = new Line2( vStartSpot, vEndSpot ); for( int i = 0; i < m_iStringCount; ++i ) { Vec2 vSpot = vStartSpot + centreLine.direction * dStringSpacing * i; d.DrawCircle( "Pickups", vSpot, 2.5 ); } // outline Line2 left = trueCentreLine.offset( dWidth / 2, Vec2.left ); Line2 right = trueCentreLine.offset( dWidth / 2, Vec2.right ); //Line2 perpendicular = trueCentreLine.perpendicular( Vec2.right ); // perpendicular.v1 = left.v1; d.DrawLine( "Pickups", left ); d.DrawLine( "Pickups", right ); double dAngle = 180 * left.direction.angleBetween( Vec2.down ) / Math.PI; d.DrawArc( "Pickups", trueCentreLine.v1, dWidth / 2, dAngle, 180 + dAngle ); d.DrawArc( "Pickups", trueCentreLine.v2, dWidth / 2, 180 + dAngle, dAngle ); }
void DrawFretMarker( Drawer d, Line2[] fretLines, int iFretNumber, bool bDouble = false ) { if( fretLines.Length < iFretNumber ) return; Line2 fret1 = fretLines[ iFretNumber - 1 ]; Line2 fret2 = fretLines[ iFretNumber ]; Line2 newLine = new Line2( ( fret1.v1 + fret2.v1 ) * 0.5, ( fret1.v2 + fret2.v2 ) * 0.5 ); if( m_eMarkerStyle == MarkerStyle.Centred ) { if( !bDouble ) { Vec2 vCentre = newLine.origin + newLine.direction * ( newLine.distance / 2 ); d.DrawCircle( "FretMarkers", vCentre, m_dDotRadius ); } else { Vec2 vCentre1 = newLine.origin + newLine.direction * ( newLine.distance * 1 / 4 ); Vec2 vCentre2 = newLine.origin + newLine.direction * ( newLine.distance * 3 / 4 ); d.DrawCircle( "FretMarkers", vCentre1, m_dDotRadius ); d.DrawCircle( "FretMarkers", vCentre2, m_dDotRadius ); } } else if( m_eMarkerStyle == MarkerStyle.Edge || m_eMarkerStyle == MarkerStyle.OpposingEdges ) { if( m_eMarkerStyle == MarkerStyle.OpposingEdges && iFretNumber > 12 ) newLine = new Line2( newLine.v2, newLine.v1 ); d.DrawCircle( "FretMarkers", newLine.origin + newLine.direction * ( m_dDotEdgeSpacing + m_dDotRadius ), m_dDotRadius ); if( bDouble ) { d.DrawCircle( "FretMarkers", newLine.origin + newLine.direction * ( m_dDotEdgeSpacing*2 + m_dDotRadius*3 ), m_dDotRadius ); } } else if( m_eMarkerStyle == MarkerStyle.SquareBlocks ) { } }
//--------------------------------------------------------------------- public void RefreshFretCharts( AxeCalc app ) { m_bassFretChartTable.Clear(); m_bassFretChartTable.Columns.Clear(); m_bassFretChartTable.Rows.Clear(); m_trebleFretChartTable.Clear(); m_trebleFretChartTable.Columns.Clear(); m_trebleFretChartTable.Rows.Clear(); Line2[] fretLines = new Line2[ m_iFretCount + 1 ]; for( int i = 0; i <= m_iFretCount; ++i ) fretLines[ i ] = GetFretLine( i ); if( !MultiScale ) { m_bassFretChartTable.Columns.Add( "Fret" ); m_bassFretChartTable.Columns.Add( "From nut" ); m_bassFretChartTable.Columns.Add( "Fret to fret" ); for( int i = 1; i <= m_iFretCount; ++i ) { object[] values = new object[ 3 ]; values[ 0 ] = i; values[ 1 ] = ( fretLines[ 0 ].v1.x - fretLines[ i ].v1.x ).ToString( "F3" ); values[ 2 ] = ( fretLines[ i - 1 ].v1.x - fretLines[ i ].v1.x ).ToString( "F3" ); if( i == 1 ) values[ 2 ] += " (nut - 1)"; else values[ 2 ] += String.Format( " ({0} - {1})", i-1, i ); m_bassFretChartTable.Rows.Add( values ); } } else { m_bassFretChartTable.Columns.Add( "Fret" ); m_bassFretChartTable.Columns.Add( "From reference" ); m_bassFretChartTable.Columns.Add( "Fret to fret" ); m_trebleFretChartTable.Columns.Add( "Fret" ); m_trebleFretChartTable.Columns.Add( "From reference" ); m_trebleFretChartTable.Columns.Add( "Fret to fret" ); // extend all the lines out to the edges of the blank Line2 blankTopLine = new Line2( 0, app.FretboardBlankWidth / 2, 1000, app.FretboardBlankWidth / 2 ); Line2 blankBottomLine = new Line2( 0, -app.FretboardBlankWidth / 2, 1000, -app.FretboardBlankWidth / 2 ); for( int i = 0; i <= m_iFretCount; ++i ) { fretLines[ i ].extendToInfinite( blankTopLine ); fretLines[ i ].extendToInfinite( blankBottomLine ); } double dReferenceX = Math.Max( fretLines[ 0 ].v1.x, fretLines[ 0 ].v2.x ); // bass side for( int i = 0; i <= m_iFretCount; ++i ) { object[] values = new object[ 3 ]; values[ 1 ] = ( dReferenceX - fretLines[ i ].v1.x ).ToString( "F3" ); if( i == 0 ) { values[ 0 ] = "nut"; values[ 2 ] = ( dReferenceX - fretLines[ i ].v1.x ).ToString( "F3" ) + " (ref - nut)"; } else { values[ 0 ] = i; values[ 2 ] = ( fretLines[ i - 1 ].v1.x - fretLines[ i ].v1.x ).ToString( "F3" ); if( i == 1 ) values[ 2 ] += " (nut - 1)"; else values[ 2 ] += String.Format( " ({0} - {1})", i - 1, i ); } m_bassFretChartTable.Rows.Add( values ); } // treble side for( int i = 0; i <= m_iFretCount; ++i ) { object[] values = new object[ 3 ]; values[ 1 ] = ( dReferenceX - fretLines[ i ].v2.x ).ToString( "F3" ); if( i == 0 ) { values[ 0 ] = "nut"; values[ 2 ] = ( dReferenceX - fretLines[ i ].v2.x ).ToString( "F3" ) + " (ref - nut)"; } else { values[ 0 ] = i; values[ 2 ] = ( fretLines[ i - 1 ].v2.x - fretLines[ i ].v2.x ).ToString( "F3" ); if( i == 1 ) values[ 2 ] += " (nut - 1)"; else values[ 2 ] += String.Format( " ({0} - {1})", i - 1, i ); } m_trebleFretChartTable.Rows.Add( values ); } } }
//--------------------------------------------------------------------- public void Draw( Drawer d ) { d.AddLayer( "Scale", Color.FromArgb( 255, 255, 255, 255 ) ); d.AddLayer( "FretCentres", Color.FromArgb( 255, 0, 192, 192 ) ); d.AddLayer( "Fretwire", Color.FromArgb( 255, 192, 192, 192 ) ); d.AddLayer( "StringCenterLines", Color.FromArgb( 255, 255, 255, 255 ) ); d.AddLayer( "Strings", Color.FromArgb( 255, 255, 255, 255 ) ); d.AddLayer( "FretBoard", Color.FromArgb( 255, 255, 255, 255 ) ); d.AddLayer( "Saddles", Color.FromArgb( 255, 255, 255, 0 ) ); d.AddLayer( "SaddleScrews", Color.FromArgb( 255, 255, 192, 0 ) ); // find out what strings we need double[] stringWidths = new double[ m_iStringCount ]; double[] stringCompensations = new double[ m_iStringCount ]; for( int i = 0; i < m_iStringCount; ++i ) { double dResultantTension = 0; StringInfo s = GetIdealString( i, ref dResultantTension ); stringWidths[ i ] = s.m_dDiameter * 25.4; stringCompensations[ i ] = GetRequiredCompensation( i, m_dStringHeightAt12th ); } RectangleF extents = RoughExtents; double fMaxScale = Math.Max( m_fBassScaleLength, m_fTrebleScaleLength ); d.SetLimits( extents.Left, extents.Top, extents.Right, extents.Bottom ); // draw centreline & lines showing the scale points for the two scales d.DrawLine( "Scale", -30, 0, fMaxScale + 30, 0 ); // d.DrawLine( "Scale", 0, TotalBridgeStringSpacing / 2 + 30, 0, -TotalBridgeStringSpacing / 2 - 30 ); // if( m_fBassScaleLength != m_fTrebleScaleLength ) // d.DrawLine( "Scale", scaleTrebleOffset, TotalBridgeStringSpacing / 2 + 30, scaleTrebleOffset, -TotalBridgeStringSpacing / 2 - 30 ); // find fret locations Line2[] fretLines = new Line2[ m_iFretCount + 1 ]; for( int i = 0; i < m_iFretCount + 1; ++i ) { fretLines[ i ] = GetFretLine( i ); } /* # do constant-spacing based string spacing, to take each string's thickness into account #spacingLeft = TotalNutStringSpacing + stringWidths[ 0 ] / 2 + stringWidths[ stringCount - 1 ] / 2 #for i in range( stringCount ): # spacingLeft -= stringWidths[ i ] #spacingBetweenStrings = spacingLeft / ( stringCount - 1.0 ) #positionUpto = 0 #stringPositions = list() #for i in range( stringCount ): # stringPositions.append( positionUpto / TotalNutStringSpacing ) # print( "string %i nut position %.3f" % (i, positionUpto )) # if( i != stringCount - 1 ): # positionUpto += stringWidths[ i ] / 2 # positionUpto += spacingBetweenStrings # positionUpto += stringWidths[ i + 1 ] / 2 */ // properly figure out the fretboard outlines, taking into account zero fret, etc etc etc... Line2 zeroFretLine = new Line2( fretLines[ 0 ] ); Line2 nutLineLeft; if( !m_bZeroFret ) nutLineLeft = zeroFretLine; else nutLineLeft = zeroFretLine.offset( m_dZeroFretNutOffset, Vec2.right ); Line2 nutLineRight = nutLineLeft.offset( m_dNutWidth, Vec2.right ); Line2 fbEndLine = new Line2( fretLines[ m_iFretCount ] ); Line2 fret12Line = fretLines[ 12 ]; Vec2 bassLine0 = new Vec2( 0, 0 ); Vec2 bassLine12th = new Vec2( 0, 0 ); zeroFretLine.intersectInfinite( new Line2( 0, FretboardWidthAtNut / 2, 100, FretboardWidthAtNut / 2 ), ref bassLine0 ); fretLines[ 12 ].intersectInfinite( new Line2( 0, FretboardWidthAt12th / 2, 100, FretboardWidthAt12th / 2 ), ref bassLine12th ); Line2 fbBassLine = new Line2( bassLine0, bassLine12th ); //new Line2( //stringTopEdges[ 0 ].offset( edgeOfFretboardSpacing, Vec2.up ); Line2 fbTrebleLine = fbBassLine.mirror( new Line2( 0, 0, 1, 0 ) ); //stringBottomEdges[ m_iStringCount - 1 ].offset( edgeOfFretboardSpacing, Vec2.down ); fbEndLine.v1.x -= 8; fbEndLine.v2.x -= 8; nutLineLeft.trimToInfinite( fbBassLine, Vec2.down ); nutLineLeft.trimToInfinite( fbTrebleLine, Vec2.up ); nutLineRight.trimToInfinite( fbBassLine, Vec2.down ); nutLineRight.trimToInfinite( fbTrebleLine, Vec2.up ); fbEndLine.trimToInfinite( fbBassLine, Vec2.down ); fbEndLine.trimToInfinite( fbTrebleLine, Vec2.up ); fbBassLine.trimToInfinite( fbEndLine, Vec2.right ); fbBassLine.trimToInfinite( nutLineRight, Vec2.left ); fbTrebleLine.trimToInfinite( fbEndLine, Vec2.right ); fbTrebleLine.trimToInfinite( nutLineRight, Vec2.left ); // draw fretboard d.DrawLine( "FretBoard", nutLineLeft ); d.DrawLine( "FretBoard", nutLineRight ); d.DrawLine( "FretBoard", fbEndLine ); d.DrawLine( "FretBoard", fbBassLine ); d.DrawLine( "FretBoard", fbEndLine ); d.DrawLine( "FretBoard", fbTrebleLine ); // draw frets for( int i = 0; i <= m_iFretCount; ++i ) { if( i == 0 && !m_bZeroFret ) continue; Line2 fret = fretLines[ i ]; fret.extendToInfinite( fbBassLine ); fret.extendToInfinite( fbTrebleLine ); d.DrawLine( "FretCentres", fret ); // fretwire Line2 fretRight = fret.offset( m_dFretwireWidth / 2, Vec2.right ); fretRight.trimToInfinite( fbBassLine, Vec2.down ); fretRight.trimToInfinite( fbTrebleLine, Vec2.up ); d.DrawLine( "Fretwire", fretRight ); Line2 fretLeft = fret.offset( m_dFretwireWidth / 2, Vec2.left ); fretLeft.trimToInfinite( fbBassLine, Vec2.down ); fretLeft.trimToInfinite( fbTrebleLine, Vec2.up ); d.DrawLine( "Fretwire", fretLeft ); // put a little ellipse at the end to make it purty //d.DrawEllipseArc( "Fretwire", fretLeft.v2, fretRight.v2, 0.5, fretLeft.v2, fretRight.v2 ); } // draw strings Line2[] stringLines = new Line2[ m_iStringCount ]; Vec2[] saddleSpots = new Vec2[ m_iStringCount ]; double dMaxSaddleX = -10000000.0f; double dMinSaddleX = 10000000.0f; for( int i = 0; i < m_iStringCount; ++i ) { stringLines[ i ] = GetStringLine( i ); stringLines[ i ].trimToInfinite( nutLineRight, Vec2.left ); // calculate the estimated string intonation point saddleSpots[ i ] = stringLines[ i ].v1 + stringLines[ i ].direction * -stringCompensations[ i ]; saddleSpots[ i ].y = stringLines[ i ].v1.y; dMaxSaddleX = Math.Max( dMaxSaddleX, saddleSpots[ i ].x ); dMinSaddleX = Math.Min( dMinSaddleX, saddleSpots[ i ].x ); // extend the string out to the saddle Line2 saddleLine = new Line2( saddleSpots[ i ].x, saddleSpots[ i ].y + 5.0f, saddleSpots[ i ].x, saddleSpots[ i ].y - 5.0f ); stringLines[ i ].extendToInfinite( saddleLine ); Line2 topEdge = stringLines[ i ].offset( stringWidths[ i ] / 2.0, Vec2.up ); Line2 bottomEdge = stringLines[ i ].offset( stringWidths[ i ] / 2.0, Vec2.down ); topEdge.trimToInfinite( nutLineRight, Vec2.left ); bottomEdge.trimToInfinite( nutLineRight, Vec2.left ); d.DrawLine( "StringCenterLines", stringLines[ i ] ); d.DrawLine( "Strings", topEdge ); d.DrawLine( "Strings", bottomEdge ); //d.DrawLine( "Saddles", saddleLine ); } // figure out where the saddle screw should go, based on its max adjustment //double dMaxSaddleAdjustment = 8.5; //double dAdjustmentRangeNeeded = dMaxSaddleX - dMinSaddleX; // DrawSaddleScrew will draw at the centre of the adjustment, so figure out an X that keeps everything close to the middle range // draw saddles & saddle screws for( int i = 0; i < m_iStringCount; ++i ) { DrawSaddle( d, saddleSpots[ i ] ); // draw min & max compensation points Vec2 minSaddleSpot = GetStringLine( i ).v1 + GetStringLine( i ).direction * -GetRequiredCompensation( i, m_dMinStringHeightAt12th ); minSaddleSpot.y = saddleSpots[ i ].y; Vec2 maxSaddleSpot = GetStringLine( i ).v1 + GetStringLine( i ).direction * -GetRequiredCompensation( i, m_dMaxStringHeightAt12th ); maxSaddleSpot.y = saddleSpots[ i ].y; //DrawSaddle( d, minSaddleSpot ); //DrawSaddle( d, maxSaddleSpot ); if( m_fBassScaleLength == m_fTrebleScaleLength ) { Vec2 screwSpot = new Vec2( saddleSpots[ i ].x, saddleSpots[ i ].y ); screwSpot.x = ( dMinSaddleX + dMaxSaddleX ) * 0.5; DrawSaddleScrew( d, screwSpot ); } else { DrawSaddleScrew( d, saddleSpots[ i ] ); } } d.AddLayer( "FretMarkers", Color.FromArgb( 255, 255, 255, 255 ) ); //d.DrawCircle( "FretMarkers", new Vec2( 0, 0 ), 4 ); DrawFretMarker( d, fretLines, 3 ); DrawFretMarker( d, fretLines, 5 ); DrawFretMarker( d, fretLines, 7 ); DrawFretMarker( d, fretLines, 9 ); DrawFretMarker( d, fretLines, 12, true ); DrawFretMarker( d, fretLines, 15 ); DrawFretMarker( d, fretLines, 17 ); DrawFretMarker( d, fretLines, 19 ); DrawFretMarker( d, fretLines, 21 ); DrawFretMarker( d, fretLines, 24, true ); // draw pickup positions DrawPickup( d, m_bridgePickup ); DrawPickup( d, m_middlePickup ); DrawPickup( d, m_neckPickup ); /* # draw some comparison pickup positions fStratNeckPos = 6.375 / 25.5 fStratMiddlePos = 3.875 / 25.5 fStratBridgePos = 1.625 / 25.5 fStratBridgeBassPos = 1.815 / 25.5 fStratBridgeTreblePos = 1.435 / 25.5 fJBNeckPos = 6 / 34.0 fJBBridgePos = 2.13 / 34.0 fPRSNeckPos = 148 / 635.0 fPRSBridgePos = 43 / 635.0 fNewNeckPos1 = interpolate( 1/3.0, fJBNeckPos, fPRSNeckPos ) fNewNeckPos2 = interpolate( 2/3.0, fJBNeckPos, fPRSNeckPos ) writeScalePos( f, fStratNeckPos, "StratPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fStratMiddlePos, "StratPickups", bridgeStringLine, nutStringLine ) writeAngledScalePos( f, fStratBridgeBassPos, fStratBridgeTreblePos, "StratPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fJBNeckPos, "JBPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fJBBridgePos, "JBPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fPRSNeckPos, "PRSPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fPRSBridgePos, "PRSPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fNewNeckPos1, "TristanPickups", bridgeStringLine, nutStringLine ) writeScalePos( f, fNewNeckPos2, "TristanPickups", bridgeStringLine, nutStringLine ) */ }
//def __repr__( self ): // return "v1" + repr( v1 ) + " v2" + repr( v2 ) + " origin" + repr( origin ) + " direction" + repr( direction ) + " distance %.5f" % distance public bool intersectInfiniteInternal( Line2 other, ref Vec2 result, ref double[] constants ) { double x1 = v1.x; double y1 = v1.y; double x2 = v2.x; double y2 = v2.y; double x3 = other.v1.x; double y3 = other.v1.y; double x4 = other.v2.x; double y4 = other.v2.y; double determinant = ( y4 - y3 ) * ( x2 - x1 ) - ( x4 - x3 ) * ( y2 - y1 ); if( determinant == 0 ) return false; constants[ 0 ] = ( ( x4 - x3 ) * ( y1 - y3 ) - ( y4 - y3 ) * ( x1 - x3 ) ) / determinant; constants[ 1 ] = ( ( x2 - x1 ) * ( y1 - y3 ) - ( y2 - y1 ) * ( x1 - x3 ) ) / determinant; result.x = x1 + constants[ 0 ] * ( x2 - x1 ); result.y = y1 + constants[ 0 ] * ( y2 - y1 ); return true; }
public bool intersectInfinite( Line2 other, ref Vec2 result ) { double[] constants = new double[ 2 ]; return intersectInfiniteInternal( other, ref result, ref constants ); }
public Line2( Line2 other ) : this(other.v1, other.v2) { }
public bool trimToInfinite( Line2 other, Vec2 sideToKeep ) { // trim to or extend to another double[] constants = new double[ 2 ]; Vec2 intersectionPoint = new Vec2( 0, 0 ); if( intersectInfiniteInternal( other, ref intersectionPoint, ref constants ) == false ) return false; // extending to another if( constants[ 0 ] > 1 ) { init( v1, intersectionPoint ); return true; } if( constants[ 0 ] < 0 ) { init( intersectionPoint, v2 ); return true; } // trimming to another //print( "trimToInfinite gave constant of %.3f" % constants[ 0 ]) Vec2 deltaToV1 = v1 - intersectionPoint; Vec2 deltaToV2 = v2 - intersectionPoint; Vec2 deltaToSide = intersectionPoint; if( deltaToV1.dot( sideToKeep ) > 0 ) { init( v1, intersectionPoint ); //print( " trimmed back in the direction of v1" ) return true; } if( deltaToV2.dot( sideToKeep ) > 0 ) { init( intersectionPoint, v2 ); //print( " trimmed back in the direction of v2" ) return true; } return false; }
public Line2 mirror( Line2 mirrorLine ) { // project each point of the line onto the mirrorline, use that as a way to construct new points Vec2 newv1 = mirrorLine.projection( v1 )*2 - v1; Vec2 newv2 = mirrorLine.projection( v2 )*2 - v2; return new Line2( newv1, newv2 ); }
public bool intersectSegment( Line2 other, ref Vec2 result ) { double[] constants = new double[ 2 ]; if( intersectInfiniteInternal( other, ref result, ref constants ) == false ) return false; if( constants[ 0 ] < 0 || constants[ 0 ] > 1 || constants[ 1 ] < 0 || constants[ 1 ] > 1 ) return false; return true; }
public void DrawLine( string strLayer, Line2 l ) { DrawLine( strLayer, l.v1.x, l.v1.y, l.v2.x, l.v2.y ); }