- Posts: 19306
- Thank you received: 0
Mesa 7i96 to spindle FWD/REV control
5 years 5 months ago #209774
by andypugh
Replied by andypugh on topic Mesa 7i96 to spindle FWD/REV control
andypugh wrote: I have VBA code that does it in Excel. Let me go to the other computer...
Code:
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
Please Log in to join the conversation.
Time to create page: 0.034 seconds
