Гост написа:IMG_20240526_113745.jpg
Благодаря!
Ще решим задачата с много и само линейна алгебра, защото всички в 7-ми клас обичат линейна алгебра.
In [652]: import numpy as np
In [654]: matrix = np.array([
...: [-4, 2, 1],
...: [4, -4, 1],
...: [3, 3, 1]
...: ])
In [655]: # Calculate the area using the determinant
In [656]: area = 0.5 * abs(np.linalg.det(matrix))
In [657]: print("The area of the triangle is:", area)
The area of the triangle is: 24.999999999999986
----------------------------------------------------------------------------------------------------------------------------------
In [658]: import numpy as np
...:
...: # Define the points A, B, and C
...: A = np.array([-4, 2])
...: B = np.array([4, -4])
...: C = np.array([3, 3])
...:
...: # Calculate vectors AB and BC
...: vector_ab = B - A # AB = B - A
...: vector_bc = C - B # BC = C - B
...:
...: # Calculate the dot product of AB and BC
...: dot_product = np.dot(vector_ab, vector_bc)
...:
...: # Calculate the magnitudes of AB and BC
...: magnitude_ab = np.linalg.norm(vector_ab)
...: magnitude_bc = np.linalg.norm(vector_bc)
...:
...: # Calculate the angle in radians and then convert to degrees
...: cos_theta = dot_product / (magnitude_ab * magnitude_bc)
...: angle_abc = np.degrees(np.arccos(cos_theta))
...:
...: print("The angle ABC is:", angle_abc, "degrees")
The angle ABC is: 135.0 degrees
-------------------------------------------------------------------------------------------------------------------------------------------------
In [659]: import numpy as np
In [660]: # Define points A, B, and C as arrays
In [661]: A = np.array([-4, 2])
In [662]: B = np.array([4, -4])
In [663]: C = np.array([3, 3])
In [664]: # Create a matrix for the points A, B, and C
In [665]: matrix = np.array([
...: [A[0], A[1], 1],
...: [B[0], B[1], 1],
...: [C[0], C[1], 1]
...: ])
In [666]: # Numerator: Calculate the absolute value of the determinant of the matrix
In [667]: numerator = abs(np.linalg.det(matrix))
In [668]: # Denominator: Calculate the distance between points A and B (the length of AB)
In [669]: denominator = np.linalg.norm(B - A)
In [670]: # Distance from point C to line AB
In [671]: distance = numerator / denominator
In [672]: print("The distance from point C to the line AB is:", distance)
The distance from point C to the line AB is: 4.999999999999997