4

我需要在这段代码中创建一个“弧”。我一直在研究其他一些成功创建圆圈的代码,但我无法理解如何正确实现开始和停止值。

本质上,代码当前仍然创建了一个圆圈,我不知道该怎么做。

这是一个较大文件的一部分,但我认为其余部分无关紧要。让我知道我是否应该添加其余部分。

class UIArc{
  float a, b, c, d, start, stop;
  public UIArc(float a, float b, float c, float d, float start, float stop){
    setArc(a, b, c, d, start, stop);
  }
  public UIArc(PVector p1, PVector p2){
    setArc(p1.x, p1.y, p2.x, p2.y, 90, 180);
  }
  void setArc(float a, float b, float c, float d, float start, float stop){
    this.a = min(a, c);
    this.b = min(b, d);
    this.c = max(a, c);
    this.d = max(b, d);
  }
  PVector getCentre(){
    float cx = (this.c - this.a)/2.0;
    float cy = (this.d = this.b)/2.0;
    return new PVector(cx, cy);
  }
  boolean isBetweenInc(float v, float lo, float hi){
    if(v >= lo && v <= hi) return true;
  return false;
  }
  boolean isPointInside(PVector p){
    if(isBetweenInc(p.x, this.a, this.c) && isBetweenInc(p.y, this.b, this.d))return true;
    return false;
  }
  float getWidth(){
    return(this.c - this.a);
  }
  float getHeight(){
    return(this.d - this.b);
  }
}
4

1 回答 1

0

我假设弧的角度以度为单位:

setArc(p1.x, p1.y, p2.x, p2.y, 90, 180);

但是角度必须以arc()弧度而不是度数传递给函数。用于radians()将度数转换为弧度。

例如

class UIArc{

    // [...]

    void setArc(float a, float b, float c, float d, float start, float stop){
        this.a = min(a, c);
        this.b = min(b, d);
        this.c = max(a, c);
        this.d = max(b, d);
        this.start = start;
        this.stop = stop;
    }

    void draw() {
        arc(this.a, this.b, this.c, this.c,
        radians(this.start), radians(this.stop));
    }
}
于 2019-05-08T16:10:16.193 回答