DESSINER UNE ELLIPSE INCLINÉE

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 28 mars 2007 à 14:55
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 29 mars 2007 à 09:53
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/41993-dessiner-une-ellipse-inclinee

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
29 mars 2007 à 09:53
cette lenteur relative ne viens pas que de ta facon de dessiner...
c'est un tout.

la precision est très importante, dejà... ca fait beaucoup de calculs pour des points que tu ne verra pas...

j'ai raccourci un peu ton code :


Option Explicit

Private Type POINTF
X As Single
Y As Single
End Type

Private nPoints As Long
Private xnPoints() As POINTF

Private Sub Form_Load()
Picture1.AutoRedraw = False

UpDown1(0).Max = CLng(Picture1.Width)
UpDown1(1).Max = CLng(Picture1.Height)
UpDown1(0).Value = CLng(Picture1.Width / 2)
UpDown1(1).Value = CLng(Picture1.Height / 2)
UpDown1(2).Value = 100
UpDown1(3).Value = 40
UpDown1(4).Value = 0
UpDown1(5).Value = 360
UpDown1(6).Value = 5
UpDown1(7).Value = 10

Text1(0).Text = UpDown1(0).Value & " pix"
Text1(1).Text = UpDown1(1).Value & " pix"
Text1(2).Text = UpDown1(2).Value & " pix"
Text1(3).Text = UpDown1(3).Value & " °"
Text1(4).Text = UpDown1(4).Value & " °"
Text1(5).Text = UpDown1(5).Value & " °"
Text1(6).Text = UpDown1(6).Value / 10
Text1(7).Text = UpDown1(7).Value & " °"

Picture1.Refresh
End Sub

Private Sub TraiterPoint(ByVal Index As Long, ByVal theta As Single, ByVal AngleRot As Single, ByVal Rapport As Single, ByVal Rayon As Single, ByVal CentreX As Single, ByVal CentreY As Single)
Dim new_x As Single
Dim new_y As Single
Dim X As Single
Dim Y As Single
X = Rayon * Cos(theta)
Y = Rayon * Sin(theta) * Rapport

new_x = X * Cos(AngleRot) + Y * Sin(AngleRot)
new_y = X * Sin(AngleRot) - Y * Cos(AngleRot)

xnPoints(nPoints).X = new_x + CentreX
xnPoints(nPoints).Y = new_y + CentreY
End Sub

Private Function DessinerEllipse(CentreX As Single, CentreY As Single, Rayon As Single, AngleRot As Single, AngleDep As Single, AngleFin As Single, Rapport As Single, Precision As Single)
Const PI As Single = 3.1415926535
Dim X As Single
Dim Y As Single
Dim theta As Single
Dim DTHETA As Single
Dim i As Long
DTHETA = Precision * PI / 180

If nPoints = 0 Then
For theta = AngleDep * PI / 180 To DTHETA + AngleFin * PI / 180 Step DTHETA
ReDim Preserve xnPoints(nPoints)
TraiterPoint nPoints, theta, AngleRot * PI / 180, Rapport, Rayon, CentreX, CentreY
nPoints = nPoints + 1
Next theta
End If

If nPoints Then
Picture1.CurrentX = xnPoints(0).X
Picture1.CurrentY = xnPoints(0).Y

For i = 1 To nPoints - 1
Picture1.Line -(xnPoints(i).X, xnPoints(i).Y)
Next i
End If
End Function

Private Sub Picture1_Paint()
DessinerEllipse UpDown1(0).Value, UpDown1(1).Value, UpDown1(2).Value, UpDown1(3).Value, UpDown1(4).Value, UpDown1(5).Value, UpDown1(6).Value / 10, UpDown1(7).Value
End Sub

Private Sub UpDown1_Change(Index As Integer)
Select Case Index
Case 0
Text1(Index).Text = UpDown1(Index).Value & " pix"
Case 1
Text1(Index).Text = UpDown1(Index).Value & " pix"
Case 2
Text1(Index).Text = UpDown1(Index).Value & " pix"
Case 3
Text1(Index).Text = UpDown1(Index).Value & " °"
Case 4
Text1(Index).Text = UpDown1(Index).Value & " °"
Case 5
Text1(Index).Text = UpDown1(Index).Value & " °"
Case 6
Text1(Index).Text = UpDown1(Index).Value / 10
Case 7
Text1(Index).Text = UpDown1(Index).Value & " °"
End Select

nPoints = 0
Picture1.Refresh
End Sub
daddycool76 Messages postés 56 Date d'inscription mardi 19 décembre 2006 Statut Membre Dernière intervention 2 juillet 2007
29 mars 2007 à 09:13
ok sympa, Merci pour les infos !!!
Le problème de cette source est qu'elle n'est pas trés optimisée niveau vitesse.
ta méthode devrai être bien plus rapide :)
@ +
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
29 mars 2007 à 09:06
mais ta version 'matheuse' est très bien ainsi ^^
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
29 mars 2007 à 08:25
tu retourne ton plan, tu dessine l'eclipse, tu remet tout en ordre.
paré pour une nouvelle eclipse ^^
daddycool76 Messages postés 56 Date d'inscription mardi 19 décembre 2006 Statut Membre Dernière intervention 2 juillet 2007
29 mars 2007 à 07:02
Bonjour Renfield,
Avec cet api (je pense) on peut appliquer une rotation à une bitmap.
Or si tu dessines plusieurs formes dans une picturebox avec les méthode line ou circle comment fais-tu pour n'incliner qu'un seul des éléments déssinés ?

@ +
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
28 mars 2007 à 14:55
ça c'est la version matheuse.

via API, on utiliserai (entre autres)
SetWorldTransform
Ellipse
Rejoignez-nous