如何创建角度并移动它

时间:2019-07-05 14:53:38

标签: java processing

我创建了一个应用程序,该应用程序使用Java和“处理”来创建诸如(线,圆)的表格。但是我无法用两条线创建一个角度,当我们单击仅一条线时,该角度会将两条线一起移动。如果您知道该怎么做或如何创建“角度”表格,我会很高兴的:)。 感谢您的帮助。

class Angle extends Form {

    private float angle;
    float rotate = 0;

    public Angle(float x, float y, float w, float h) {
        super(x, y, w, h);

    }

    public void draw() {
        fill(this.c.get("red"), this.c.get("green"), this.c.get("blue"));
        pushMatrix();
        rotate(this.rotate);
        noStroke();

        if (this.selected) {
            fill(255, 0, 0);
            //strokeWeight(3);
            //stroke(3);
        }

        rect(this.x, this.y, this.w, this.h);
        popMatrix();
    }

    public void setSize(float d) {
    }

    public boolean onOver(float x, float y) {
        float dx = this.x - x;
        float dy = this.y - y;
        float h = sqrt(sq(dx) + sq(dy));
        float e = atan(dy / dx);
        float angle = e + this.rotate;
        float o = h * sin(angle);
        float a = h * cos(angle);

        if (o <= this.h + 25 / 2 && a <= this.w) {
            return true;
        } else {
            return false;
        }
    }

    public void setRotate(float a) {
    }
}
class FormManager {

    private ArrayList<Form> forms;
    private Form target;

    public FormManager() {
        this.forms = new ArrayList<Form>();
    }

    public void createForm(String type) {
        switch (type) {
            case "circle":
                this.forms.add(this.forms.size(), new Circle(width / 2, height / 2, 300));
                break;

            case "line":
                this.forms.add(this.forms.size(), new Line(width / 2, height / 2, 200, 15));
                break;

            case "angle":
                this.forms.add(this.forms.size(), new Line(width / 2, height / 2, 200, 15));
                this.forms.add(this.forms.size(), new Line(width / 2, height / 2, 15, 200));
                break;
        }
    }

    public Form getTarget() {
        return this.target;
    }

    public void setTarget(Form target) {
        if (this.target != null && target != this.target) {
            this.target.endSelect();
        }

        this.target = target;
        this.target.onSelect();
    }

    public void deleteTarget() {
        println("DELETE", this.target);
        this.forms.remove(this.target);
        this.target = null;
    }

    public Form getForm(int i) {
        return this.forms.get(i);
    }

    public ArrayList<Form> getForms() {
        return this.forms;
    }
}

0 个答案:

没有答案