[6.44] Nest min() in max() to limit an argument
You can limit an argument to two bounds upper and lower, with this expression:
max(lower,min(x,upper))
For example, suppose we have a calculation in which we calculate the real inverse sine (arcsine) of the
result of a previous calculation. Round-off errors in that calculation may result in an argument x whose
absolute value is slightly greater than 1, so finding the inverse sine of the argument will result in an
error, or a complex result. We can avoid this by finding the inverse sine of
max(-
1
,min(x,
1
))
If x is between -1 and 1, inclusive, then the expression returns x. If x is less than -1, the expression
returns -1, and if x is greater than 1, the expression returns 1. This same result can be obtained with an
If ... EndIf structure, or as a when() function, but this form is more concise.
[6.45] Determine if a point is inside a triangle
This tip is more application-specific than most, but the idea is so clever that I had to include it. Suppose
that we have a triangle defined by the three points A, B and C, with rectangular coordinates (x
a
,y
a
),
(x
b
,y
b
) and (x
c
,y
c
). We have another point P at (x,y), and we want to know if P is inside the triangle ABC.
In general, if P is in ABC, then the area of ABC will equal the sum of the areas of the three triangles
PBC, APC and ABP. If P is outside ABC, then the area of ABC is less than the sum of the areas of the
three triangles formed by A, B, C and P. To find the area of a triangle with points P
1
, P
2
and P
3
, we can
use
area(P
1
P
2
P
3
) =
=
x1 y1 1
x2 y2 1
x3 y3 1
2
abs
x1y2
+
x3y1
+
x2y3
−
x1y3
−
x2y1
−
x3y2
2
where the double bars indicate the absolute value of the determinant of the matrix. By using the
absolute value, we ensure that the area is positive, regardless of the ordering of the three points. This
function implements the idea:
PntTrian(px,py,ax,ay,bx,by,cx,cy,tol)
Func
©(px,py,ax,ay,bx,by,cx,cy,tol) return True if point P is in triangle ABC
©25may0
1
/dburkett@infinet.com
local tArea,at
©Define local function to find triangle area
Define tArea(xx
1
,yy
1
,xx2,yy2,xx3,yy3)=Func
abs(xx
1
*yy2-xx
1
*yy3-xx2*yy
1
+xx2*yy3+xx3*yy
1
-xx3*yy2)/2
EndFunc
©Find area difference & return result
tArea(ax,ay,bx,by,cx,cy)
→
at
6 - 78
Summary of Contents for TI-92+
Page 52: ...Component side of PCB GraphLink I O connector detail 1 41...
Page 53: ...LCD connector detail PCB switch side 1 42...
Page 54: ...Key pad sheet contact side Key pad sheet key side 1 43...
Page 55: ...Key cap detail 1 44...
Page 57: ...Component side of PCB with shield removed A detail view of the intergrated circuits 1 46...
Page 410: ...void extensionroutine2 void Credit to Bhuvanesh Bhatt 10 4...