Home > Community > Forums > PCB SKILL > Angle between two segments

Email

Recipients email * (separate multiple addresses with commas)

Message *

 Send yourself a copy

Subscribe

Intro copy of the newsletter section here, some intro copy of the newsletter. Instruction of how to subscribe to this newsletter.

First Name *

Last Name *

Email *

Company / Institution *

 Send Yourself A Copy

Angle between two segments

Last post Mon, Oct 29 2012 1:39 AM by luanvn81. 2 replies.
 Started by luanvn81 26 Oct 2012 02:06 AM. Topic has 2 replies and 693 views
• Fri, Oct 26 2012 2:06 AM

• luanvn81
• Joined on Fri, Sep 18 2009
• dnai, Vietnam
• Posts 58
• Points 875
Angle between two segments
 Hi all !My code to check if an angle betwween two segments is 90 degrees or not. here it is : ................................................... first_seg = car(cline_seg)second_seg = nthelem(2,cline_seg)x11=caar(first_seg->startEnd)        y11=cadar(first_seg->startEnd)x12=car(lastelem(first_seg->startEnd))y12=lastelem(lastelem(first_seg->startEnd))x21=caar(second_seg->startEnd)        y21=cadar(second_seg->startEnd)x22=car(lastelem(second_seg->startEnd))y22=lastelem(lastelem(second_seg->startEnd))a = axlDistance(x11:y11, x12:y12)b = axlDistance(x21:y21, x22:y22)c = axlDistance(x11:y11, x22:y22)if(c*c == (a*a + b*b) thenfprintf(writeOutFile, "Location (%L %L)\n", x12,y12));end if  ...................................   the result are:   " E- *Error* range: argument #1 should be a number (type template = "n") - nil  ". I think axlDistance command have got error,  but only command  a = axlDistance(x11:y11, x12:y12) is OK. How can I fix it? Please help me.PS:  x11,y11 --------------------x12,y12                    x21,y21--------------------x22,y22 (x11, y11) (x12,y12) =  (-19885.0 26245.0) (-19885.0 26400.0) (x21, y21) (x22,y22) =  (-19885.0 26400.0) (-19985.0 26500.0)
• Post Points: 20
• Fri, Oct 26 2012 9:53 AM

• knuhcrek
• Joined on Tue, Jul 29 2008
• Posts 7
• Points 95
Re: Angle between two segments
 why use axlDistance at all?  Use the dot product. If the dot product of the two segments equals zero then the segments are at right-angles to each other.`procedure( calcDotProduct( ptA ptB ptC ptD)prog(( dot_product)dot_product = 0.0  ; cosine of angle between segments -- segs are perpendicular when == 0ptA.x = xCoord( ptA)ptA.y = yCoord( ptA)ptB.x = xCoord( ptB)ptB.y = yCoord( ptB)ptC.x = xCoord( ptC)ptC.y = yCoord( ptC)ptD.x = xCoord( ptD)ptD.y = yCoord( ptD);rintf("ptA.x= %n  ptA.y= %n  ptB.x= %n  ptB.y= %n\n", ptA.x ptA.y ptB.x ptB.y);rintf("ptC.x= %n  ptC.y= %n  ptD.x= %n  ptD.y= %n\n", ptC.x ptC.y ptD.x ptD.y)dot_product = (ptB.y - ptA.y)*(ptD.y - ptC.y) + (ptB.x - ptA.x)*(ptD.x - ptC.x);rintf("dot product= %1.6f\n", dot_product)return( dot_product));end-prog);end-procedure `HTH, Chris Waltersrusty former Cadence guru
• Post Points: 20
• Mon, Oct 29 2012 1:39 AM

• luanvn81
• Joined on Fri, Sep 18 2009
• dnai, Vietnam
• Posts 58
• Points 875
Re: Angle between two segments
 Hi Chris!   Your code really help me so much, my skill now works OK. thank you very much.Luan.
• Post Points: 5