• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. Angle between two segments

Stats

  • Replies 2
  • Subscribers 160
  • Views 12945
  • Members are here 0
More Content

Angle between two segments

luanvn81
luanvn81 over 12 years ago

 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)

 

 

  • Sign in to reply
  • Cancel
  • knuhcrek
    knuhcrek over 12 years ago

    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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • luanvn81
    luanvn81 over 12 years ago

     Hi Chris!

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

    Luan.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information