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

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 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 761 views
Page 1 of 1 (3 items)
Sort Posts:
  • Fri, Oct 26 2012 2:06 AM

    • luanvn81
    • Top 150 Contributor
    • Joined on Fri, Sep 18 2009
    • dnai, Vietnam
    • Posts 61
    • Points 920
    Angle between two segments Reply

     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) then
    fprintf(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
    • Not Ranked
    • Joined on Tue, Jul 29 2008
    • Posts 7
    • Points 95
    Re: Angle between two segments Reply

    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 == 0

    ptA.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 Walters

    rusty former Cadence guru

    • Post Points: 20
  • Mon, Oct 29 2012 1:39 AM

    • luanvn81
    • Top 150 Contributor
    • Joined on Fri, Sep 18 2009
    • dnai, Vietnam
    • Posts 61
    • Points 920
    Re: Angle between two segments Reply

     Hi Chris!

       Your code really help me so much, my skill now works OK. thank you very much.

    Luan.

    • Post Points: 5
Page 1 of 1 (3 items)
Sort Posts:
Started by luanvn81 at 26 Oct 2012 02:06 AM. Topic has 2 replies.