Mesa 7i96 to spindle FWD/REV control

More
21 May 2021 18:30 #209774 by andypugh

I have VBA code that does it in Excel. Let me go to the other computer...

Function INTERPXY(Optional ZValues As Range, Optional X As Double, Optional Y As Double, Optional Xaxis As Range, Optional Yaxis As Range) As Double
 
    Dim Xmax, Xmin, Ymax, Ymin, Ystart, q1 As Integer
    Dim V, V1, V2, V3, V4 As Double
    Dim dx, dy As Double
    
    
           
    If Xaxis Is Nothing Then Set Xaxis = ZValues.Resize(RowSize:=1).Offset(RowOffset:=-1)
    If Yaxis Is Nothing Then Set Yaxis = ZValues.Resize(ColumnSize:=1).Offset(ColumnOffset:=-1)

            
' Find X bracket

            Xmax = 0
            Xmin = 1
            Do
                Xmax = Xmax + 1
                If X >= Xaxis(1, Xmax).Value Then Xmin = Xmax
            Loop Until Xmax >= Xaxis.Count Or Xaxis(1, Xmax).Value >= X

            
' Find Y bracket

            Ymin = 1
            Ymax = 0
            Do
                Ymax = Ymax + 1
                If Y >= Yaxis(Ymax, 1).Value Then Ymin = Ymax
            Loop Until Ymax >= Yaxis.Count Or Yaxis(Ymax, 1).Value >= Y
            
' Set 4 corner values
' V1 V2
' V3 V4
            
            V1 = ZValues(Ymin, Xmin).Value
            V2 = ZValues(Ymin, Xmax).Value
            V4 = ZValues(Ymax, Xmax).Value
            V3 = ZValues(Ymax, Xmin).Value
            
            If Xmax <> Xmin Then
            dx = (X - Xaxis(1, Xmin).Value) / (Xaxis(1, Xmax).Value - Xaxis(1, Xmin).Value)
            Else
            dx = 0
            End If
            
            If Ymax <> Ymin Then
            dy = (Y - Yaxis(Ymin, 1).Value) / (Yaxis(Ymax, 1).Value - Yaxis(Ymin, 1).Value)
            Else
            dy = 0
            End If
                        
            INTERPXY = (1 - dx) * (1 - dy) * V1 + dx * (1 - dy) * V2 + (1 - dx) * dy * V3 + dx * dy * V4
    
   
End Function
The following user(s) said Thank You: mhd325ic

Please Log in or Create an account to join the conversation.

More
23 May 2021 11:19 #209888 by mhd325ic
Thanks Andy, This helps a lot!

Please Log in or Create an account to join the conversation.

Moderators: PCWjmelson
Time to create page: 0.210 seconds
Powered by Kunena Forum