الفرق بين المراجعتين ل"Algorithms/equation plane passing 3 points"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
 
سطر 163: سطر 163:
  
 
<source lang="text">equation of plane is  26 x + 7 y + 9 z + 3 = 0.</source>
 
<source lang="text">equation of plane is  26 x + 7 y + 9 z + 3 = 0.</source>
 
 
 
== مصادر ==
 
== مصادر ==
  

المراجعة الحالية بتاريخ 09:49، 3 مارس 2020

تحسب هذه الخوارزمية معادلة المستوى الذي يمرّ عبر ثلاث نقاط معرّفة بإحداثياتها (x1, y1, z1) و (x2, y2, z2) و (x3, y3, z3).

مثال:

Input: x1 = -1 y1 = w z1 = 1
x2 = 0 y2 = -3 z2 = 2
x3 = 1 y3 = 1 z3 = -4
Output: equation of plane is 26 x + 7 y + 9 z + 3 = 0.

Input: x1 = 2, y1 = 1, z1 = -1, 1
x2 = 0, y2 = -2, z2 = 0
x3 = 1, y3 = -1, z3 = 2
Output: equation of plane is -7 x + 5 y + 1 z + 10 = 0.

مبدأ عمل الخوارزمية

لنفترض أن النقاط الثلاثة هي P و Q و R وتمتلك هذه النقاط الإحداثيات (x1, y1, z1) و (x2, y2, z2) و (x3, y3, z3) على التوالي.

تكون معادلة المستوى وفقًا لهذه المعطيات:

a * (x – x0) + b * (y – y0) + c * (z – z0) = 0

تمثّل a وb و c نسب الاتجاه الخاصة بناظم المستوى normal، والإحداثيات (x0, y0, z0) هي إحداثيات أيّ من النقاط الثلاثة (أي P أو Q أو R) التي تمرّ عبر المستوى. ولحساب نسب الاتجاهات لناظم المستوى يمكن أخذ أي متجهين في المستوى، وليكونا المتجه PQ والمتجه PR.

=> Vector PQ = (x2 - x1, y2 - y1, z2 - z1) = (a1, b1, c1).
=> Vector PR = (x3 - x1, y3 - y1, z3 - z1) = (a2, b2, c2).

المتّجه الناظم لهذا المستوى سيكون المتّجه PQ × PR:

=> PQ X PR = (b1 * c2 - b2 * c1) i 
              + (a2 * c1 - a1 * c2) j 
              + (a1 * b2 - b1 *a2) k = ai + bj + ck.

a, b, c ستكون نسب الاتجاهات لناظم المتجه، وبأخذ أي نقطة من النقاط P أو Q أو R وبفرض أنّ إحداثياتها هي (x0, y0, z0) فإنّ معادلة المستوى الذي يمرّ عبر النقطة (x0, y0, z0) وتمتلك نسب الاتجاهات a, b, c ستكون:

=> a * (x - x0) + b * (y - y0) + c * (z - z0) = 0.
=> a * x - a * x0 + b * y - b * y0 + c * z - c * z0 = 0.
=> a * x + b * y + c * z + (- a * x0 - b * y0 - c * z0) = 0.

تنفيذ الخوارزمية

تعرض الأمثلة التالية طريقة تنفيذ الخوارزمية في عدد من لغات البرمجة:

  • C++‎:
#include <bits/stdc++.h> 
#include<math.h> 
#include <iostream> 
#include <iomanip> 

using namespace std; 

void equation_plane(float x1, float y1, 
					float z1, float x2, 
					float y2, float z2, 
					float x3, float y3, float z3) 
{ 
	float a1 = x2 - x1; 
	float b1 = y2 - y1; 
	float c1 = z2 - z1; 
	float a2 = x3 - x1; 
	float b2 = y3 - y1; 
	float c2 = z3 - z1; 
	float a = b1 * c2 - b2 * c1; 
	float b = a2 * c1 - a1 * c2; 
	float c = a1 * b2 - b1 * a2; 
	float d = (- a * x1 - b * y1 - c * z1); 
	std::cout << std::fixed; 
	std::cout << std::setprecision(2); 
	cout << "equation of plane is " << a << " x + " << b 
		<< " y + " << c << " z + " << d << " = 0."; 
} 

// اختبار الدالة السابقة
int main() 
{ 
	
	float x1 =-1; 
	float y1 = 2; 
	float z1 = 1; 
	float x2 = 0; 
	float y2 =-3; 
	float z2 = 2; 
	float x3 = 1; 
	float y3 = 1; 
	float z3 =-4; 
	equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3); 
	return 0; 
}
  • بايثون:
def equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3): 
	
	a1 = x2 - x1 
	b1 = y2 - y1 
	c1 = z2 - z1 
	a2 = x3 - x1 
	b2 = y3 - y1 
	c2 = z3 - z1 
	a = b1 * c2 - b2 * c1 
	b = a2 * c1 - a1 * c2 
	c = a1 * b2 - b1 * a2 
	d = (- a * x1 - b * y1 - c * z1) 
	print "equation of plane is ", 
	print a, "x +", 
	print b, "y +", 
	print c, "z +", 
	print d, "= 0."

# اختبار الدالة السابقة
x1 =-1
y1 = 2
z1 = 1
x2 = 0
y2 =-3
z2 = 2
x3 = 1
y3 = 1
z3 =-4
equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3)
  • جافا:
import java .io.*; 

class GFG 
{ 
	
static void equation_plane(float x1, float y1, 
						float z1, float x2, 
						float y2, float z2, 
						float x3, float y3, 
						float z3) 
{ 
	float a1 = x2 - x1; 
	float b1 = y2 - y1; 
	float c1 = z2 - z1; 
	float a2 = x3 - x1; 
	float b2 = y3 - y1; 
	float c2 = z3 - z1; 
	float a = b1 * c2 - b2 * c1; 
	float b = a2 * c1 - a1 * c2; 
	float c = a1 * b2 - b1 * a2; 
	float d = (- a * x1 - b * y1 - c * z1); 
	System.out.println("equation of plane is " + a + 
					" x + " + b + " y + " + c + 
					" z + " + d + " = 0."); 
} 

// اختبار التابع السابق
public static void main(String[] args) 
{ 
	float x1 =-1; 
	float y1 = 2; 
	float z1 = 1; 
	float x2 = 0; 
	float y2 =-3; 
	float z2 = 2; 
	float x3 = 1; 
	float y3 = 1; 
	float z3 =-4; 
	equation_plane(x1, y1, z1, x2, 
				y2, z2, x3, y3, z3); 
} 
}

تعطي الشيفرات السابقة المخرجات التالية:

equation of plane is  26 x + 7 y + 9 z + 3 = 0.

مصادر