Sub BTFLIPV_Cliquer()
ActiveSheet.Shapes("ligne").Flip msoFlipVertical
End Sub
Sub BTFLIPH_Cliquer()
ActiveSheet.Shapes("ligne").Flip msoFlipHorizontal
End Sub
Sub BTGO_Cliquer()
CalculerDiagonaleRectangle2
End Sub
Sub CalculerDiagonaleRectangle2()
On Error Resume Next
ActiveSheet.Shapes("controleur").Delete
On Error GoTo 0
Dim Lg#, HT, Diagonale#, DiffWidth, L1#, L2
Set SHAP = ActiveSheet.Shapes("ligne")
Set shap2 = ActiveSheet.Shapes("rectrouge")
'données de base
Lg = SHAP.Width 'largeur
HT = SHAP.Height 'hauteur
tp = SHAP.Top 'top
bottom = SHAP.Top + SHAP.Height 'bottom
'Diagonale = Sqr(Ht ^ 2 + Lg ^ 2)'méthode math abrogée
newtp = shap2.Top
newht = bottom - newtp
newlg = Lg / (HT / newht) 'reduit la largeur au même ratio que la reduction du height
DiffWidth = Abs(Lg - newlg)
'MsgBox HT & vbCrLf & Lg & vbCrLf & vbCrLf & newht & vbCrLf & newlg
'visuel de l'intersection des deux rectangles en ajoutant un rectangle vide borduré
Set Shp = ActiveSheet.Shapes.AddShape(1, SHAP.Left, bottom - newht, newlg, newht)
Shp.Name = "controleur"
Shp.Fill.Visible = False
Shp.Line.ForeColor.RGB = vbGreen
With shap2
L1 = SHAP.Left + newlg - (shap2.Width / 2)
L2 = SHAP.Left + DiffWidth - (shap2.Width / 2)
If SHAP.VerticalFlip Then
If SHAP.HorizontalFlip Then .Left = L2 Else .Left = L1
If SHAP.HorizontalFlip Then Shp.Left = SHAP.Left + SHAP.Width - Shp.Width Else Shp.Left = SHAP.Left
Else
If SHAP.HorizontalFlip Then .Left = L1 Else .Left = L2
Shp.Left = SHAP.Left + DiffWidth
If SHAP.HorizontalFlip Then Shp.Left = SHAP.Left Else Shp.Left = SHAP.Left + SHAP.Width - Shp.Width
End If
End With
End Sub
Option Explicit
Function GetDiagonalPositionLeft(SHAP, SHAP2) As Double
'*****************************************
'Reposition in terms of left a shape(1) at the intersection of another shape(2) of type "MsoLine" according to the top of the shapes(1)
'Version coded by patricktoulon
'Version1 1.0
'Date version:08/04/2024
'Request from @Dudu2 in a discussion on ExcelDownloads
'https://excel-downloads.com/threads/vba-determiner-la-pente-de-la-forme-ligne-ou-fleche-ou-mieux-son-equation.20082379/page-2#posts
'*****************************************
Dim Lg#, HT#, Tp#, NewTp#, NewLg#, NewHt, Bottom#, DiffWidth, L1#, L2, LF#
'Position data and size of the shapes (SHAP2 = "LINE")
Lg = SHAP.Width 'Width of shape (MsoLine)
HT = SHAP.Height 'Height of shape (MsoLine)
Tp = SHAP.Top 'Top of shape (MsoLine)
Bottom = SHAP.Top + SHAP.Height 'Bottom of shape (MsoLine)
NewTp = SHAP2.Top 'Width of shape(Msoline or MsoArrow
NewHt = Bottom - NewTp 'Height of intersection rectangle
NewLg = Lg / (HT / NewHt) 'Reducing the width of the rectangle to the same ratio as reducing its height
DiffWidth = Abs(Lg - NewLg) 'Difference in width of the two occupation rectangles
'Two possibilities of left according to the vertical and horizontal flip rotation
L1 = SHAP.Left + NewLg - (SHAP2.Width / 2)
L2 = SHAP.Left + DiffWidth - (SHAP2.Width / 2)
'Selection of one of the two possibilities depending on the flip
If SHAP.VerticalFlip Then
If SHAP.HorizontalFlip Then LF = L2 Else LF = L1
Else
If SHAP.HorizontalFlip Then LF = L1 Else LF = L2
End If
GetDiagonalPositionLeft = LF
End Function
Sub applique() 'SUB DE TEST
Dim X#
With ActiveSheet
X = GetDiagonalPositionLeft(.Shapes("ligne"), .Shapes("rectrouge"))
.Shapes("rectrouge").Left = X
End With
End Sub
If (.VerticalFlip = msoTrue And .HorizontalFlip = msoFalse) Or (.VerticalFlip = msoFalse And .HorizontalFlip = msoTrue)
If .VerticalFlip + .HorizontalFlip = 1
Tant que tu n'en es pas à z=x+i*y, ça va.il semble qu'on dise maintenant y = mx + p mais je le fais à l'ancienne
Si tu parles de mon code, non. Car, pour déterminer l'équation de la ligne, je prends en compte les Flips V et H. Le fameux test simplifiable par @TooFatBoy Flip V + Flip H = -1.et re teste normalement un des deux test doit être faux