الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

calculate the closest points

مغلق
بدأه sarah2010 في 17 فبراير 2010 · 1 رد · 501 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

الله يرضى عنكم ممكن تساعدوني في هذا البرنامج

طبعا‘ البرنامج مكتمل بس المشكلة عندي في الكلاس Test

عندي مجموعة نقاط كما هو موضح في البرنامج

MyPoints[] points=new MyPoints[8];
points[0]= new MyPoints(-1,-1);
points[1]= new MyPoints(-1,3);
points[2]= new MyPoints(1,1);// the closest 2 points between this point and (2,0.5)point
points[3]= new MyPoints(2,0.5);
points[4]= new MyPoints(2,-1);
points[5]= new MyPoints(4,-0.5);
points[6]= new MyPoints(4,2);
points[7]= new MyPoints(3,3);

و المطلوب اني احسب المسافه بين كل نقطتين واقرب نقطتين يعطيني المسافه بينهما.

طبعا النقطتين القريبتين من بعض هما

points[2]= new MyPoints(1,1);// the closest 2 points between this point and (2,0.5)point
points[3]= new MyPoints(2,0.5);

انا سالت المدرس قال لي المشكلة في الشرط حاولت كثييييييييييير في اني اغير الشرط بس ما ضبط معي

اليكم البرنامج

package assignmentnumber3;
public class Test{


public static void main(String[]args){
//i.Create two MyPoints: one at 10,10, and the other at 20,20.
MyPoints p1 = new MyPoints(10,10);
MyPoints p2 = new MyPoints(20,20);
MyCircle c1 = new MyCircle(10,10,10);
//Create an array of MyPoint and initialize them to the following values.
MyPoints[] points=new MyPoints[8];
points[0]= new MyPoints(-1,-1);
points[1]= new MyPoints(-1,3);
points[2]= new MyPoints(1,1);// the closest points between this point and (2,0.5)point
points[3]= new MyPoints(2,0.5);
points[4]= new MyPoints(2,-1);
points[5]= new MyPoints(4,-0.5);
points[6]= new MyPoints(4,2);
points[7]= new MyPoints(3,3);

double minVal = Double.MAX_VALUE;

for (int i = 0; i<points.length;i++){
for (int j = i+1; j<points.length;j++){

//calculate the distance between p1 and p2
 double distance = points.distance(points[j]);

 if (minVal<distance)

 minVal = distance;

}//end for
}//end for
System.out.println(minVal);

}//end main
}

وهذه هي معادلة حساب المسافة الموجودة في الكلاس MyPoints

public double distance(MyPoints a){
return Math.sqrt(Math.pow(this.x-a.x,2)+Math.pow(this.y-a.y,2));}

تم تعديل هذه المشاركة بواسطة herch في 17 فبراير 2010 في 22:21

#2

يا أختي طرحتي موضوعاً مشابهاً من قبل

وهذا الموضوع لا يضيف جديداً

الموضوع مغلق

برجاء الإضافة على الموضوع القديم

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

هذا الموضوع مغلق.

مواضيع مشابهة