Page 1 of 1

Line with Relative Angle in Code

Posted: Wed Jan 21, 2015 7:26 pm
by wildspidee
I need to draw a line with a relative angle of 90 degrees to an existing line. I output the angle of the existing line with getAngle(), which returns 3.372995491. When I view the line properties in the drawing the Angle is 193.258406.

I referred to the LineRelativeAngle.js for help and saw the getRelativeAngle(). Assuming my problem was a coordinate issue, I copied over parts of the .getLine function and included the Line.js at the top of my page. That was a complete failure.

I'm not sure where the 3.372995491 angle is coming from, so I don't know how to work with it. Can you clarify, please?

Thank you,
Lori

Re: Line with Relative Angle in Code

Posted: Thu Jan 22, 2015 3:40 am
by wildspidee
Here's a couple more instances of my angle problems. I've taken images of the property editor after the entities are draw and here's the corresponding code snippets (there is a line and a text entity).

Code: Select all

    var grainText = new RTextData(
            lgrain.getMiddlePoint(),                 // position
            lgrain.getMiddlePoint(),                 // alignment point
            2.0,                 // height
            2.0,                 // text width (ignored for now)
            RS.VAlignBottom,        // alignments
            RS.HAlignLeft,
            RS.LeftToRight,
            RS.Exact,
            1.0,                 // line spacing factor
            "Grainline",              // the text
            "Arial",      // font
            false,        // bold
            false,        // italic
            90.0,          // angle
            false         // simple text without formatting
    );

Code: Select all

 var grainX = markB.getX() - (lB_G.getLength() / 2);
    var grainY = markB.getY() + (lA_B.getLength() / 6);
    var grainLen = (lA_B.getLength()*0.67);
    var mGrain = new RVector(grainX,grainY);
    var lgrain = new RLine(mGrain,90.0,grainLen);

Re: Line with Relative Angle in Code

Posted: Thu Jan 22, 2015 9:34 am
by andrew
wildspidee wrote:I need to draw a line with a relative angle of 90 degrees to an existing line. I output the angle of the existing line with getAngle(), which returns 3.372995491. When I view the line properties in the drawing the Angle is 193.258406.
All angles used internally by QCAD are represented in radian, not degrees. Note that also the standard ECMAScript angle functions work in radian (Math.sin, Math.cos, etc).

Image
Image

The angles displayed to or input by the user are converted to / from degrees.

Re: Line with Relative Angle in Code

Posted: Thu Jan 22, 2015 4:18 pm
by wildspidee
With that, it was easy to fix my problems. One entire pattern is now being generated accurately from script. I've hard coded my variables at the top, so the next step is the QT XML work.

Thank you Andrew.