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

حساب المسافة بين النقاط

بدأه sarah2010 في 3 فبراير 2010 · 4 رد · 1,882 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

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

اولا البرنامج يتكون من ثلاثة classes(MCircle ,MyPoints ,Test)

المطلوب من Class MyCircle حساب اذا كانت النقاط الموجودة فيTest class موجودة في حدود الدائرة ام لا.فإذا كانت مو في داخل الدائرة سوف تعيد القيمة true , اذا كانت النقاط في خارج الدائرة تعيد False

واليكم هذا جزء من الكود

public boolean MyCircle(MyPoints a){
//if(distance(a,x,y,radius)<= radius)
if(this.a<=radius)
     return true;
else return false;
}

المطلوب الثاني هو فحص اذا كانت الدائرة ممكن ان تحتوى ع دائرة مكتملة في داخلها ام لا.

//ix. A method named contains that return true if and only if the MyCircle completely contains a MyCircle passed as a parameter.
public boolean MyCircle(MyCircle b){
if (radius)
return true
else return false;
//x. A toString method.

3) المطلوب الثالث حساب الاصغر مساحة بين النقطتين (هذا موجود في Test Class)

طبعا حاولت اعملة بهذا الشكل

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);
        //ii.Create a MyCircle centered at one of your MyPoints from i, with radius of 10.
    MyCircle c1 = new MyCircle(10,10,10);
   //iii.Check and see if the other MyPoint from i, is contained in the MyCircle from
   //step ii.

    //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);
    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);
//MyPoints[][]c =new MyPoints[8][8];
//MyPoints [][] c={{-1,-1},{-1,3},{1,1},{2,0.5},{2,-1},{4,-0.5},{4,2},{3,3}};

    int val1 = 0, val2 =1;
    double shortestDistances = distance(points[val1][0],points[val1][1],points[val2][0],points[val2][1]);

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

            double distance = distance(points[0],points[1],points[j][0],points[j][1]);
            if (shortestDistances> distance)
                val1 = i;
                val2= j;
                shortestDistances = distance;
        }//end for
    }//end for
    }//end main
    System.out.println("The closest two points are ("+points[val1][0]+" , "points[val1][1]+" and "+points[val2][0]+" , "+
            points[val2][1]);
}           public static double distance(double x1,double y1,double,double x2,double x6);
        return Math.sqrt(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)

}

}




package assignmentnumber3;

public class MyCircle {
private double x,y,radius;

//A constructor has three double parameters for x, y, and radius
public MyCircle(double x,double y, double radius){
this.x = x;
this.y = y;
this.radius= radius;
}//End MyCircle Constructoe
public MyCircle(MyPoints a,double radius){
this.x=a.getX();
this.y=a.getY();
this.radius =radius;
}
//iv. A no-arg constructor that creates a circle at (0,0) with radius 1. This
//constructor should call the constructor in iii.
public MyCircle(){
this(0,0,1);
}
//v. Three get methods for the x, y and radius properties.
public double getX(){return x;}
public double getY(){return y;}
public double getRadius(){ return radius;}
//vi. Three set methods for the x, y and radius properties.
 public void setX(){this.x= x;}
 public void setY(){this.y=y;}
 public void setRadius(){this.radius= radius;}

//vii. A method named distance that returns the distance (a double) between this MyCircle and another MyCircle.
 public double distance(double a,double x,double y,double radius){
 return a =Math.sqrt(Math.pow(this.x-x,2)-Math.pow(this.y-y,2));
 }
 //viii. A method named contains that returns true if and only if the MyCircle contains a MyPoint passed as a parameter.
//passing MyPoints as a Parameter in MyCircle Class
 public boolean MyCircle(MyPoints a){
//if(distance(a,x,y,radius)<= radius)
if(this.a<=radius)
     return true;

else return false;
}
//ix. A method named contains that return true if and only if the MyCircle completely contains a MyCircle passed as a parameter.
public boolean MyCircle(MyCircle b){
if (radius)
return true
else return false;
//x. A toString method.
public String toString(){
//return "The distination between "+x+" and "+y +" is "+a;
    return "Circle: at x ="+x+" y= "+y+" and radius "+radius ;
}

}//end class MyCircle

تم تعديل هذه المشاركة بواسطة Eisa Ayed في 3 فبراير 2010 في 12:31 — السبب: missing code tag

#2

لم أستطع فهم ما تحتاجه بالضبط

برجاء إعادة كتابة المشاركة مرة أخرى

نصيحة: إذا أردت أن تعرف هل يستطيع الناس فهم ما تكتب حاول أن تقرأه قبل أن تنشره

تحياتي

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

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

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

728x90.png

#3

حتى نستطيع افادتك تحتاج لوضع الـ declaration على الأقل للفئتين MyCircle و MyPoint.

و الله ولى التوفيق

مدونتي: C++ Tips and Tricks

#4

عفواً برنامجي يتكون من 3 classes الاول هو MyCircle

package Practice;
public class MyCircle {
private double x,y,radius;
//A constructor has three double parameters for x, y, and radius
public MyCircle(double x,double y, double radius){
this.x = x;
this.y = y;
this.radius= radius;
}//End MyCircle Constructoe
public MyCircle(MyPoints a,double radius){
this.x=a.getX();
this.y=a.getY();
this.radius =radius;
}
//iv. A no-arg constructor that creates a circle at (0,0) with radius 1. This
//constructor should call the constructor in iii.
public MyCircle(){
this(0,0,1);
}
//v. Three get methods for the x, y and radius properties.
public double getX(){return x;}
public double getY(){return y;}
public double getRadius(){ return radius;}
//vi. Three set methods for the x, y and radius properties.
public void setX(int x){this.x= x;}
public void setY(int y){this.y=y;}
public void setRadius(int radius){this.radius= radius;}
//vii. A method named distance that returns the distance (a double) between this MyCircle and another MyCircle.
public double distance(double a,double x,double y,double radius){
return a =Math.sqrt(Math.pow(this.x-x,2)-Math.pow(this.y-y,2));
}
//viii. A method named contains that returns true if and only if the MyCircle contains a MyPoint passed as a parameter.
//passing MyPoints as a Parameter in MyCircle Class
public boolean contains(MyPoints a){
if(distance(a.getX(),a.getY(),a.getRadius())<= radius) //to call the methods from the distance
//if(this.a<=radius)
return true;
else return false;
}
//ix. A method named contains that return true if and only if the MyCircle completely contains a MyCircle passed as a parameter.
public boolean contains(MyCircle b){
if (radius)
return true;
else return false;}
//x. A toString method.
public String toString()
{
 return "Circle: at x ="+x+" y= "+y+" and radius "+radius ;
}
}//end class MyCircle

الثاني MyPoints Class

package Practice;
public class MyPoints {
private double x,y;
MyPoints(double x,double y){
this.x = x;
this.y = y;
}
MyPoints(){
this(0,0);
}
public double getX(){
return x;}
public double getY(){
return y;}
public double setX(){return x;}
public double setY(){return y;}
// not sure
public double distance(double a){
return a = y-x;}
public double distance(double a,double x,double y){
return a = y-x;}
public String toString(){
return "The distance between "+y+" and "+x;}
public static void main(String[]args){
 MyPoints p1;
 MyPoints p2;
p1= new MyPoints(10,10);
p2 = new MyPoints(20,20);
System.out.print("The value of P1 is "+p1+" and the value of P2 is "+p2);
}//end main
}//end class

والثالث Test Class

package practice;
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);
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);

MyPoints temp;
for (int i = 0; i<points.length;i++){
for (int j = i+1; j<points.length;j++){
if (points<points[j]){
    temp = points;}
else if (points[i+1]<points[j+1]){
    temp = points[i+1];}
else if (points[i+2]<points[j+2]){
    temp = points[i+2];}
else if (points[i+3]<points[j+3]){
    temp= points[i+3];}
else if (points[i+4]<points[j+4]){
    temp= points[i+4];}
else if (points[i+5]<points[j+5]){
    temp= points[i+5];}
else if (points[i+6]<points[j+5]){
    temp= points[i+4];}
System.out.println("The smallest points are "+temp);
}//end for
}//end for
}//end main
}

المطلوب هو ان نقوم بحساب اقرب نقطتين موجودتين في Test Class لان النقاط الثمانية موجودة فيه

MyPoints[] points=new MyPoints[8];
points[0]= new MyPoints(-1,-1);
points[1]= new MyPoints(-1,3);
points[2]= new MyPoints(1,1);
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);

بس كيف ممكن احسب المسافة بين هاي النقاط ؟

تم تعديل هذه المشاركة بواسطة علاء الصالحي في 8 فبراير 2010 في 03:21 — السبب: إضافة وسم code على الفئة test

#5

بمعادلة إقليدس

الجذر التربيعي لحاصل (طرح الإحداثيات السينية x مربع + طرح الإحداثيات الصادية y مربع)

تحياتي

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

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

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

728x90.png

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