How to you get at the angle of a line in Ravel land? Here's a snapshot of what I am after. We need to make sure the line is around 30 degrees. i.e. Between MIN=29.9 and MAX=30.1
You can find the angle using 'axis_angle' measurement.
(axis_angle object1 object2) => Measures the smallest angle (in degrees) between the objects.
There are a couple of different measurements for working with angles, depending on which angle you are looking for. The angle measurement returns the counter-clockwise angle between two linear objects in the range [0, 360]. The principal_value measurement can be used to normalize this angle to the range [-180, 180]. There is also axis_angle, which treats two linear objects as directionless axes and returns the smallest angle between them, which is going to be in the range [0, 90].
I was not familiar with this "normalized" segment angle displayed in the Show Element window, but it seems to be the counter-clockwise angle within the quadrant from x or y coordinate axis to the segment. This angle will be the same regardless of segment direction, it will just shift the quadrant. If we have the angle from a unit vector [1, 0] to the segment, the normalized angle na can be expressed as a mod 90, or the reminder after dividing a with 90. Like in many programming languages, mod only works on integer numbers in Ravel, so we will have to express this a bit more convoluted as na = a - 90(floor(a/90)).
Suppose that you have a relation mysegment with the segments that you want to check. You could then find this angle by:
(define mysegment_angle (transform (s) mysegment (s (angle (CREATE_VECTOR 1 0) s))))(define mysgement_normalized (transform (s a) mysegment_angle (s a - 90.0*(floor a/90.0))))
You would then subtract this from your constraint value and compare the absolute value with some epsilon.
In reply to Bjoern L:
Thanks for the help. What is this (CREATE_VECTOR) function above? I thought maybe it was built-in until I got:
E- *Error* No such derivation or measurement create_vector
Can you "draw" a new line with some make line or vector function? (makeLine (start_point myLine), (point (xcoordinate myLine + 100), (ycoordinate myLine)) )So the same starting point as the trace line but add 100 to the X (and the same Y of course so it is horizontal) and then use the angle function with those 2 lines?
My email is rchipman @ micron .com if you need the .SIP file or just want to get in touch. Thanks, Rian
In reply to Rian Chipman:
CREATE_VECTOR is in the Ravel Standard Library.
Purpose: Create a vector from the origin to the given coordinates. Syntax (CREATE_VECTOR x/number y/number) => vector/vector
If you don't have RSLYou can add this before your code.
(macro CREATE_VECTOR (X Y) "CREATE_VECTOR x/number y/number => vector/vector
Create a vector from the origin to the given coordinates." (connecting_line (create_point 0.0 0.0) (create_point X Y)))
In reply to Kirti Sikri:
Thanks. Turned out just the angle function and that "normalized" principal_value function did the trick (which is good because I never could get that CREATE_VECTOR to work). Here's the complete code:
(constraint MIN_ANGLE 29.9)(constraint MAX_ANGLE 30.1)
(define PlatingTrace (select (mLine) line (and (layer? mLine, "SUBSTRATE GEOMETRY/UNITBOT_PLTG_RT") ; RT = Routed (length mLine) < 10000.0 ; Exclude main vertical line segment ) ))
; Go 1000 out on the X axis but same Y axis so it is horizontal; Yes end_point is the end of the line next to the middle vertical line
(define BadAngles (select (mLine, mAngle) (transform (mLine) PlatingTrace (mLine, (abs (principal_value (angle mLine, (connecting_line (end_point mLine), (create_point 1000.0 (ycoordinate (end_point mLine)))))))) ) (or ; angle must be between 29.9 and 30.1 so errors are outside this range < 29.9 OR > 30.1 (mAngle < (value MIN_ANGLE)) (mAngle > (value MAX_ANGLE)) ) ))