用于创建圆形对象的构造函数javascript

用于创建圆形对象的构造函数javascript,javascript,object,methods,constructor,geometry,Javascript,Object,Methods,Constructor,Geometry,我想创建一个构造函数来创建圆形对象。我需要添加两种方法。我希望第一个方法(translate())接受两个数字参数,并将第一个参数添加到圆的x坐标,将第二个参数添加到圆的y坐标 我希望第二个方法取一个圆参数,如果两个圆相交,则返回yes,否则返回false function Circle (xPoint, yPoint, radius) { this.x = xPoint; this.y = yPoint; this.r = radius; } function translate(

我想创建一个构造函数来创建圆形对象。我需要添加两种方法。我希望第一个方法(translate())接受两个数字参数,并将第一个参数添加到圆的x坐标,将第二个参数添加到圆的y坐标

我希望第二个方法取一个圆参数,如果两个圆相交,则返回yes,否则返回false

function Circle (xPoint, yPoint, radius) {
this.x = xPoint; 
this.y = yPoint;  
this.r = radius;  
}

function translate(horiz, vert) {
return ((horiz + this.x) && (vert + this.y));
}
如何实现第二个intersects()方法?

给您:

function Circle(x, y, r) {

    this.x = x;
    this.y = y;
    this.r = r;

    this.translate = function(h, v) {
        this.x += h;
        this.y += v;
    };

    this.intersect = function(circle) {
        var centerDistance = Math.pow(this.x - circle.x, 2) + Math.pow(this.y - circle.y, 2);
        return Math.pow(this.r - circle.r, 2) <= centerDistance && centerDistance <= Math.pow(this.r + cirle.r, 2);
    };

}
功能圆(x、y、r){
这个.x=x;
这个。y=y;
这个。r=r;
this.translate=函数(h,v){
这个.x+=h;
这是y+=v;
};
this.intersect=函数(圆){
var centerDistance=Math.pow(this.x-circle.x,2)+Math.pow(this.y-circle.y,2);

首先返回Math.pow(this.r-circle.r,2),这不是一个真正的OO方法。
this.y
没有引用
circle
对象……其次,你已经为
intersect()
方法尝试了什么,为什么它不起作用?[对于交集算法的讨论,如果它们相交,您将如何使此返回为真?