Line with Relative Angle in Code

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Line with Relative Angle in Code

Post by wildspidee » Wed Jan 21, 2015 7:26 pm

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

wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Re: Line with Relative Angle in Code

Post by wildspidee » Thu Jan 22, 2015 3:40 am

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);
Attachments
Text.jpg
Text.jpg (149.76 KiB) Viewed 6458 times
LineUnderText.jpg
LineUnderText.jpg (130.96 KiB) Viewed 6458 times

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Line with Relative Angle in Code

Post by andrew » Thu Jan 22, 2015 9:34 am

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.

wildspidee
Full Member
Posts: 84
Joined: Sat Nov 03, 2012 2:00 am

Re: Line with Relative Angle in Code

Post by wildspidee » Thu Jan 22, 2015 4:18 pm

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.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”