[SOLVED] RRay bug or misunderstanding?

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
smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

[SOLVED] RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 1:56 pm

Hi,

I tried to intersect two RRay objects, but the result is "not as expected". Given to already existing lines, I created two RRays thereof and intersect them:
this.rayAlign = new RRay(this.lineAlign.getStartPoint(), this.lineAlign.getEndPoint());
this.rayDest = new RRay(this.lineDest.getStartPoint(), this.lineDest.getEndPoint());

var inters = this.rayAlign.getIntersectionPoints(this.rayDest);
The code above does not give the valid intersection points (if startet with script debugger on, there are several unexpected debug-messages). Using RLines instead of RRays like the following variant delivers the correct intersection points, if scaling is big enough to have lines intersected:
this.rayAlign = new RLine(this.lineAlign.getStartPoint(), this.lineAlign.getEndPoint());
this.rayDest = new RLine(this.lineDest.getStartPoint(), this.lineDest.getEndPoint());

this.rayAlign.scale(this.scaling, this.lineAlign.getMiddlePoints()[0]);
this.rayDest.scale(this.scaling, this.lineDest.getMiddlePoints()[0]);

var inters = this.rayAlign.getIntersectionPoints(this.rayDest);
I don't know wheter if this is a bug or if I missed something using RRays - aren't those just RLines with infinitive length?
Last edited by smf on Tue Dec 16, 2014 8:59 pm, edited 1 time in total.

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

Re: RRay bug or misunderstanding?

Post by andrew » Tue Dec 16, 2014 3:04 pm

I'd have to see the actual coordinates to see if this is a bug.

I like to test such situations in simple test scripts like this:

File test.js:
var r1 = new RRay(new RVector(10,10), new RVector(1,0));
var r2 = new RRay(new RVector(50,0), new RVector(0,1));
var inters = r1.getIntersectionPoints(r2);
qDebug(inters);
Such a script can be run directly, using QCAD as interpreter only:

Code: Select all

./qcad -autostart test.js
Output:

Code: Select all

Debug:    RVector(50, 10, 0)

smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

Re: RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 4:46 pm

Thank you for the fast response and the hint about qDebug. My first mistake was a misunderstanding in the RRay constructor: the second parameter is "direction" and not "end point". e_surprised So RRay is with respect to the constructor not an replacement for infinite RLine. I should have rtfm better... :oops: Sorry.

Anyhow, the intersection is still not what I expect. My testscript is:

Code: Select all

//globals
var scaling=new RVector(1000, 1000);

//setting up the "clicked" lines
var d=new RLine(new RVector(812.542, 546.024, 0), new RVector(828.48, 541.753, 0));
var a=new RLine(new RVector(179.749, 96.7045, 0), new RVector(184.019, 80.7667, 0));

//getting intersection of orthogonal rays with RLine
var lrd=new RLine(d.getStartPoint(), d.getEndPoint());
lrd.rotate(Math.PI / 2, d.getMiddlePoints()[0]);
lrd.scale(scaling, d.getMiddlePoints()[0]);
var lra=new RLine(a.getStartPoint(), a.getEndPoint());
lra.rotate(Math.PI / 2, a.getMiddlePoints()[0]);
lra.scale(scaling, a.getMiddlePoints()[0]);
var ilda = lrd.getIntersectionPoints(lra);
qDebug(ilda);

//getting intersection of orthogonal rays with RRay
var rrd=new RRay(d.getStartPoint(), new RVector(d.getEndPoint().getX()-d.getStartPoint().getX(), d.getEndPoint().getY()-d.getStartPoint().getY()));
rrd.rotate(Math.PI / 2, d.getMiddlePoints()[0]);
var rra=new RRay(a.getStartPoint(), new RVector(a.getEndPoint().getX()-a.getStartPoint().getX(), a.getEndPoint().getY()-a.getStartPoint().getY()));
rra.rotate(Math.PI / 2, a.getMiddlePoints()[0]);
var irda = rrd.getIntersectionPoints(rra);
qDebug(irda);
the output is (second line is empty after "Debug"):

Code: Select all

Debug:    RVector(738.504, 237.863, 0) 
Debug:     
It seems as if I'm doing something more the wrong way. :(

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

Re: RRay bug or misunderstanding?

Post by andrew » Tue Dec 16, 2014 4:56 pm

Bit complicated.. ;)

Can you output the rays used for the calculation:
qDebug("first ray:", rrd);
qDebug("second ray:", rra);
qDebug("result:", irda);

smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

Re: RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 5:49 pm

This gives me:

Code: Select all

Debug:    RVector(738.504, 237.863, 0) 
Debug:    first ray: RRay(RShape(address: "0x1795a20"), basePoint: RVector(818.375, 535.92, 0), directionVector: RVector(4.271, 15.938, 0)) 
Debug:    second ray: RRay(RShape(address: "0x17962f0"), basePoint: RVector(173.915, 86.6006, 0), directionVector: RVector(15.9378, 4.27, 0)) 
Debug:    result:  
I'm using QCad 3.6.0 Pro under XUbuntu 14.04 LTS.
Last edited by smf on Tue Dec 16, 2014 8:09 pm, edited 2 times in total.

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

Re: RRay bug or misunderstanding?

Post by andrew » Tue Dec 16, 2014 6:23 pm

I'm not at my desktop now, but these rays don't look like they intersect.
Perhaps enter these rays into a QCAD drawing..

smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

Re: RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 6:59 pm

Thank you for the response. What makes me wonder is: the RLines are intersecting correctly, so I would assume that RRays would do at the same position. Perhaps I'm still using RRays wrong? At the moment the workaround with scaled RLines is fine - so no hurry. :)

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

Re: RRay bug or misunderstanding?

Post by andrew » Tue Dec 16, 2014 8:43 pm

smf wrote:

Code: Select all

Debug:    first ray: RRay(RShape(address: "0x1795a20"), basePoint: RVector(818.375, 535.92, 0), directionVector: RVector(4.271, 15.938, 0)) 
Debug:    second ray: RRay(RShape(address: "0x17962f0"), basePoint: RVector(173.915, 86.6006, 0), directionVector: RVector(15.9378, 4.27, 0)) 
So I've entered these rays into QCAD for you:
Screen Shot 2014-12-16 at 20.41.32.png
Screen Shot 2014-12-16 at 20.41.32.png (20.01 KiB) Viewed 9338 times
There is no intersection point, which appears to be correct.

smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

Re: RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 8:58 pm

Thank you very much - so this prooves that I had another misunderstanding: I thought of a ray being infinite in both directions. :(

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

Re: RRay bug or misunderstanding?

Post by andrew » Tue Dec 16, 2014 9:29 pm

smf wrote:Thank you very much - so this prooves that I had another misunderstanding: I thought of a ray being infinite in both directions. :(
No. That would be an XLine (RXLine).

smf
Premier Member
Posts: 177
Joined: Tue Feb 28, 2012 1:05 pm

Re: [SOLVED] RRay bug or misunderstanding?

Post by smf » Tue Dec 16, 2014 10:11 pm

Thanks again. :) With RXLine and the correct constructor usage the result for

Code: Select all

//globals
var scaling=new RVector(1000, 1000);

//setting up the "clicked" lines
var d=new RLine(new RVector(812.542, 546.024, 0), new RVector(828.48, 541.753, 0));
var a=new RLine(new RVector(179.749, 96.7045, 0), new RVector(184.019, 80.7667, 0));

//getting intersection of orthogonal rays with RLine
var lrd=new RLine(d.getStartPoint(), d.getEndPoint());
lrd.rotate(Math.PI / 2, d.getMiddlePoints()[0]);
lrd.scale(scaling, d.getMiddlePoints()[0]);
var lra=new RLine(a.getStartPoint(), a.getEndPoint());
lra.rotate(Math.PI / 2, a.getMiddlePoints()[0]);
lra.scale(scaling, a.getMiddlePoints()[0]);
var ilda = lrd.getIntersectionPoints(lra);
qDebug("scaled line:", ilda);

//getting intersection of orthogonal xlines with EXLine
var rrd=new RXLine(d.getStartPoint(), new RVector(d.getEndPoint().getX()-d.getStartPoint().getX(), d.getEndPoint().getY()-d.getStartPoint().getY()));
rrd.rotate(Math.PI / 2, d.getMiddlePoints()[0]);
var rra=new RXLine(a.getStartPoint(), new RVector(a.getEndPoint().getX()-a.getStartPoint().getX(), a.getEndPoint().getY()-a.getStartPoint().getY()));
rra.rotate(Math.PI / 2, a.getMiddlePoints()[0]);
var irda = rrd.getIntersectionPoints(rra);
qDebug("plain xline:", irda);
is :D

Code: Select all

Debug:    scaled line: RVector(738.504, 237.863, 0) 
Debug:    plain xline: RVector(738.504, 237.863, 0) 

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”