Outils pour utilisateurs

Outils du site


helloworld:algorithms:geometrie

Vérifier que 4 points forment un rectangle

On calcule la distance des 4 cotés. On vérifie que les distances sont les mêmes deux à deux.

On calcule la distance entre les points 1 et 3 et les points 2 et 4. La distance doit être la même.

How to check if given four points form a rectangle Archive le 26/09/2020

Vérifier si un point est à l'intérieur d'un polygone

Calculer une moyenne d'angles

On fait la moyenne des sinus et cosinus puis on calcul l'arctan de l'angle.

$ \bar s = \frac{1}{3} \left( \sin (355^\circ) + \sin (5^\circ) + \sin (15^\circ) \right) = \frac{1}{3} \left( -0.087 + 0.087 + 0.259 \right) \approx 0.086 $

$ \bar c = \frac{1}{3} \left( \cos (355^\circ) + \cos (5^\circ) + \cos (15^\circ) \right) = \frac{1}{3} \left( 0.996 + 0.996 + 0.966 \right) \approx 0.986 $

$ \bar \theta = \left. \begin{align} & \arctan \left( \frac{\bar s}{ \bar c} \right) & \bar s > 0 ,\ \bar c > 0 \\ & \arctan \left( \frac{\bar s}{ \bar c} \right) + 180^\circ & \bar c < 0 \\ & \arctan \left (\frac{\bar s}{\bar c} \right)+360^\circ & \bar s <0 ,\ \bar c >0 \end{align} \right\} = \arctan \left( \frac{0.086}{0.986} \right) = \arctan (0.087) = 5^\circ. $

Mean of circular quantities Archive du 20/09/2020 le 29/09/2020

Calculer le point d'intersection de deux lignes définies par chacune par deux points

def line_intersection(line1, line2):
  xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
  ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])
 
  def det(a, b):
    return a[0] * b[1] - a[1] * b[0]
 
  div = det(xdiff, ydiff)
  if div == 0:
    raise Exception('lines do not intersect')
 
  d = (det(*line1), det(*line2))
  x = det(d, xdiff) / div
  y = det(d, ydiff) / div
  return x, y
 
print line_intersection(((x1, y1), (x2, y2)), ((x3, y3), (x4, y4)))

How do I compute the intersection point of two lines? Archive du 19/12/2013 le 29/09/2020

Calculer le point d'intersection de deux segments définis par chacune par deux points

constexpr bool is_segment_intersection(float p0_x, float p0_y, float p1_x, float p1_y, 
  float p2_x, float p2_y, float p3_x, float p3_y)
{
  float s1_x = p1_x - p0_x;
  float s1_y = p1_y - p0_y;
  float s2_x = p3_x - p2_x;
  float s2_y = p3_y - p2_y;
 
  float div = -s2_x * s1_y + s1_x * s2_y;
  if (div == 0.)
    return false;
  float s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / div;
  float t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / div;
 
  return s >= 0 && s <= 1 && t >= 0 && t <= 1;
 
  // Point d'intersection :
  // i_x = p0_x + (t * s1_x);
  // i_y = p0_y + (t * s1_y);
}

How do you detect where two line segments intersect? Archive du 18/02/2009 le 09/10/2020

Calculer la droite perpendiculaire à une droite passant par un point

Le concept consiste à calculer le point sur la ligne d'origine.

Soit (x1, y1) et (x2, y2) la droite et (x3, y3) le point en dehors de la droite.

La ligne perpendiculaire à (x1, y1) et (x2, y2) passant par (x3, y3) est la droite (x3, y3) et (x4, y4)

$k = ((y2-y1) * (x3-x1) - (x2-x1) * (y3-y1)) / ((y2-y1)^2 + (x2-x1)^2)$

$x4 = x3 - k * (y2-y1)$

$y4 = y3 + k * (x2-x1)$

Perpendicular on a line from a given point Archive du 28/11/2009 le 27/11/2020

Calculer la distance entre une ligne et un point

Soit (x0, y0) et (x1, y1) la droite et (x, y) le point en dehors de la droite.

$$\frac{|(y_0-y_1)x+(x_1-x_0)y+x_0 y_1-x_1 y_0|}{\sqrt{(x_1-x_0)^2+(y_1-y_0)^2}}$$

Lines and Distance of a Point to a Line Archive du 2012 le 01/12/2020

helloworld/algorithms/geometrie.txt · Dernière modification : 2020/12/01 09:29 de root