Bonjour, je suis développeur et je dois faire une sorte de radar en 2D.
Pour placer mes points sur le radar j'ai une distance par rapport au centre du radar (un cercle) et un angle par rapport l'axe d'origine X passant par le centre du cercle.
J'ai décidé d'utiliser la conversion de coordonnées polaire en cartésien pour placer mes points, mais quelque chose m'échappe...
J'ai codé un petit bout de php pour que vous compreniez mieux mon problème.
Le résultat devrais afficher toutes les coordonnées des points pour chaque degré.Code PHP:
<?php
$rayon = 5;
for($angle = 0; $angle <= 360; $angle++)
{
echo "---------------------------------------</br>";
echo "Rayon = ".$rayon." Angle = ".$angle."</br>";
echo "X = ".$rayon." * cos(".$angle.") = ".($rayon*cos($angle))."</br>";
echo "Y = ".$rayon." * sin(".$angle.") = ".($rayon*sin($angle))."</br>";
}
?>
Voici le résultat: (désolé pour la longueur )
---------------------------------------
Rayon = 5 Angle = 0
X = 5 * cos(0) = 5
Y = 5 * sin(0) = 0
---------------------------------------
Rayon = 5 Angle = 1
X = 5 * cos(1) = 2.7015115293407
Y = 5 * sin(1) = 4.2073549240395
---------------------------------------
Rayon = 5 Angle = 2
X = 5 * cos(2) = -2.0807341827357
Y = 5 * sin(2) = 4.5464871341284
---------------------------------------
Rayon = 5 Angle = 3
X = 5 * cos(3) = -4.9499624830022
Y = 5 * sin(3) = 0.70560004029934
---------------------------------------
Rayon = 5 Angle = 4
X = 5 * cos(4) = -3.2682181043181
Y = 5 * sin(4) = -3.7840124765396
---------------------------------------
Rayon = 5 Angle = 5
X = 5 * cos(5) = 1.4183109273161
Y = 5 * sin(5) = -4.7946213733157
---------------------------------------
Rayon = 5 Angle = 6
X = 5 * cos(6) = 4.8008514332518
Y = 5 * sin(6) = -1.3970774909946
---------------------------------------
Rayon = 5 Angle = 7
X = 5 * cos(7) = 3.7695112717165
Y = 5 * sin(7) = 3.2849329935939
---------------------------------------
Rayon = 5 Angle = 8
X = 5 * cos(8) = -0.72750016904307
Y = 5 * sin(8) = 4.9467912331169
---------------------------------------
Rayon = 5 Angle = 9
X = 5 * cos(9) = -4.5556513094234
Y = 5 * sin(9) = 2.0605924262088
---------------------------------------
Rayon = 5 Angle = 10
X = 5 * cos(10) = -4.1953576453823
Y = 5 * sin(10) = -2.7201055544468
---------------------------------------
Rayon = 5 Angle = 11
X = 5 * cos(11) = 0.022128489940254
Y = 5 * sin(11) = -4.9999510327535
---------------------------------------
Rayon = 5 Angle = 12
X = 5 * cos(12) = 4.2192697936625
Y = 5 * sin(12) = -2.6828645900022
[...]
---------------------------------------
Rayon = 5 Angle = 36
X = 5 * cos(36) = -0.63981844813702
Y = 5 * sin(36) = -4.9588942672156
---------------------------------------
Rayon = 5 Angle = 37
X = 5 * cos(37) = 3.8270702597267
Y = 5 * sin(37) = -3.217690666785
---------------------------------------
Rayon = 5 Angle = 38
X = 5 * cos(38) = 4.7753682202365
Y = 5 * sin(38) = 1.4818428935469
---------------------------------------
Rayon = 5 Angle = 39
X = 5 * cos(39) = 1.3332146617997
Y = 5 * sin(39) = 4.8189769314204
---------------------------------------
Rayon = 5 Angle = 40
X = 5 * cos(40) = -3.3346903082613
Y = 5 * sin(40) = 3.7255658023967
---------------------------------------
Rayon = 5 Angle = 41
X = 5 * cos(41) = -4.9366963876191
Y = 5 * sin(41) = -0.79311334402354
---------------------------------------
Rayon = 5 Angle = 42
X = 5 * cos(42) = -1.9999265749418
Y = 5 * sin(42) = -4.5826077395782
---------------------------------------
Rayon = 5 Angle = 43
X = 5 * cos(43) = 2.7755665076031
Y = 5 * sin(43) = -4.158873713143
---------------------------------------
Rayon = 5 Angle = 44
X = 5 * cos(44) = 4.9992165432385
Y = 5 * sin(44) = 0.088509625527068
---------------------------------------
Rayon = 5 Angle = 45
X = 5 * cos(45) = 2.6266099440886
Y = 5 * sin(45) = 4.2545176226706
---------------------------------------
Rayon = 5 Angle = 46
X = 5 * cos(46) = -2.1608897244239
Y = 5 * sin(46) = 4.508941738244
---------------------------------------
Rayon = 5 Angle = 47
X = 5 * cos(47) = -4.9616773457546
Y = 5 * sin(47) = 0.61786561372612
---------------------------------------
Rayon = 5 Angle = 48
X = 5 * cos(48) = -3.200721697346
Y = 5 * sin(48) = -3.8412733066183
---------------------------------------
[...]
---------------------------------------
Rayon = 5 Angle = 81
X = 5 * cos(81) = 3.8834299101082
Y = 5 * sin(81) = -3.1494399713723
---------------------------------------
Rayon = 5 Angle = 82
X = 5 * cos(82) = 4.7483884894127
Y = 5 * sin(82) = 1.5661439121654
---------------------------------------
Rayon = 5 Angle = 83
X = 5 * cos(83) = 1.2477005898667
Y = 5 * sin(83) = 4.8418223055009
---------------------------------------
Rayon = 5 Angle = 84
X = 5 * cos(84) = -3.4001174779367
Y = 5 * sin(84) = 3.6659516003665
---------------------------------------
Rayon = 5 Angle = 85
X = 5 * cos(85) = -4.9218832169702
Y = 5 * sin(85) = -0.88037809974294
---------------------------------------
Rayon = 5 Angle = 86
X = 5 * cos(86) = -1.9184922247487
Y = 5 * sin(86) = -4.6172922350203
---------------------------------------
Rayon = 5 Angle = 87
X = 5 * cos(87) = 2.8487516713266
Y = 5 * sin(87) = -4.1090891831541
---------------------------------------
Rayon = 5 Angle = 88
X = 5 * cos(88) = 4.9968664184756
Y = 5 * sin(88) = 0.1769915136683
---------------------------------------
Rayon = 5 Angle = 89
X = 5 * cos(89) = 2.5508852247083
Y = 5 * sin(89) = 4.3003470290623
---------------------------------------
Rayon = 5 Angle = 90
X = 5 * cos(90) = -2.2403680806459
Y = 5 * sin(90) = 4.4699833180028
---------------------------------------
Rayon = 5 Angle = 91
X = 5 * cos(91) = -4.971837304641
Y = 5 * sin(91) = 0.52993755875578
---------------------------------------
Rayon = 5 Angle = 92
X = 5 * cos(92) = -3.1322222395517
Y = 5 * sin(92) = -3.897330348079
---------------------------------------
Rayon = 5 Angle = 93
X = 5 * cos(93) = 1.5871435075985
Y = 5 * sin(93) = -4.7414107063497
---------------------------------------
Rayon = 5 Angle = 94
X = 5 * cos(94) = 4.8472968333499
Y = 5 * sin(94) = -1.2262599273383
---------------------------------------
Rayon = 5 Angle = 95
X = 5 * cos(95) = 3.6508678049741
Y = 5 * sin(95) = 3.4163085736806
---------------------------------------
[...]
---------------------------------------
Rayon = 5 Angle = 359
X = 5 * cos(359) = 3.268104036224
Y = 5 * sin(359) = 3.7841109931418
---------------------------------------
Rayon = 5 Angle = 360
X = 5 * cos(360) = -1.4184554574326
Y = 5 * sin(360) = 4.7945786170715
Pourquoi pour un angle de 90 degré je n'ai pas comme résultat X=0, Y=5?
Pourquoi pour un angle de 360 degré je n'ai pas comme résultat X=5, Y=0?
J'aimerais savoir j'ai fait une erreur?
J'espère avoir été clair
Merci de votre aide par avance.
-----