Constructed arrow in (FLTK-) GUI



  • Dear experts,

    (Entschuldigt bitte, dass ich auf Englisch poste):

    I am rather new to FLTK so please forgive the beginner question:

    I try to create an arrow on a canvas (window). Canvas Pixels start with 0,0 in the left upper corner.

    Arrow: Starting with a line defined by two points (start/end) with start being supposed to be the upper right corner (= Quadrant 1 for the beginning) I would like to get the small arrow heads (left and right) of the line. I tried it like this:

    In main():

    Arrow a(Point(500,200), Point(200,600)); //start and end-point arrow should look to Northeast

    Now I would like to draw the "hook" but alway with the same angle relative to the axis of a's root:

    I tried and played around with many sinuses and atans like:

    Arrow::Arrow(Point st, Point en) : start(st), end(en) {

    double dx = (st.x - en.x);
    double dy = -(st.y - en.y);
    double alpha = atan(dx/dy)*180/PI, delta = 25;
    double xl, yl, xr=0, yr=0;

    l.add(st, en); // Collection/container of lines-objects defined by two Points

    xl = st.y * sin(delta) + st.x * cos(delta);
    yl = st.y * cos(delta) - st.x * sin(delta);
    xr = st.y * sin(180-delta) + st.x * cos(180-delta);
    yr = st.y * cos(180-delta) - st.x * sin(180-delta);

    cout << "Start x: " << st.x << " / y: " << st.y << endl;
    cout << "End x: " << en.x << " / y: " << en.y << endl;
    cout << "Height: " << dx << " / Width: " << dy << endl;
    cout << "xl: " << xl << endl << "yl: " << yl << endl;
    cout << "xr: " << xr << endl << "yr: " << yr << endl;
    cout << "Alpha = Arctan (" << dx << "/" << dy << "): " << alpha << endl;

    l.add(st, Point(xl,yl));
    l.add(st, Point(xr,yr));

    }

    The small tops go everywhere but I cannot see any systematic.

    Can anyone please advice?

    Thanks a lot.

    Best regards

    Joerg


Anmelden zum Antworten