As I wrote yesterday:
-> Well... If you do some subtractions so as to put the apex point at
-> the origin, so the coordinates of the other two points are referred
-> to it, then you can easily calculate the angle between the (new)
-> X-axis and each of the lines from the origin to the other two points.
-> Basically, it's just ATN(Y/X), where X and Y are the coordinates of
-> the other point. However, you'd have to put in some coding to deal
-> with the possibility that X might be zero, in which case the angle
-> would be SGN(Y)*PI/2, and also to add PI to the ATN result if X is
-> negative. (I think that's right!)
->
-> When you've got the two angles between the X-axis and the two lines,
-> all you have to do is subtract these angles to get the angle between
-> the two lines. Take its ABSolute value and, if necessary, subtract
-> from 2*PI so as to make the result no greater than PI. (Presumably,
-> you want to calculate the *internal* angle of the triangle!)
Just for the heck of it, I tried coding it up:
100 'calculate angle defined by x,y of 3 points
110 '
120 DEFDBL A - Z
130 DEFINT J
140 DIM X(2), Y(2), A(2)
150 PI=4*ATN(1)
160 '
170 'input co-ordinates of the 3 points
180 PRINT "First point entered will be apex of angle"
190 PRINT
200 FOR J = 0 TO 2
210 PRINT "For point # "; J + 1
220 INPUT "X co-ordinate"; X(J)
230 INPUT "Y co-ordinate"; Y(J)
240 PRINT
250 NEXT
260 '
270 FOR J = 1 TO 2 'for each non-apex point
280 'calculate x and y relative to apex
290 X(J) = X(J) - X(0)
300 Y(J) = Y(J) - Y(0)
310 'calculate angle between line from apex to point and x-axis
320 IF X(J)=0 THEN A(J)=SGN(Y(J))*PI/2 ELSE
A(J)=ATN(Y(J)/X(J))-PI*(X(J)<0)
330 NEXT
340 '
350 'calculate angle between lines
360 A=ABS(A(1)-A(2))
370 IF A>PI THEN A=2*PI-A
380 '
390 'print out result
400 PRINT "Angle is ";A;" radians, or ";A*180/PI;" degrees."
Ooops! Line 320 seems to have been wrapped onto two lines of this
message. Unwrap it before running it!
Anyway, it seems to work just fine. Sorry the BASIC is a bit archaic.
It's all I have here. But it does the job.
dow
--- QScan/PCB v1.19b / 01-0150
---------------
* Origin: Pro-Mail Communications - Toronto Canada (1:250/1004)
|