--- a/Point.st Tue Apr 01 18:05:27 1997 +0200
+++ b/Point.st Wed Apr 02 00:15:36 1997 +0200
@@ -88,6 +88,23 @@
"Modified: 8.5.1996 / 20:01:50 / cg"
!
+r:distance theta:angleInRadians
+ "create and return a new point given polar coordinates.
+ The angle is given in radians"
+
+ |x y|
+
+ x := distance * angleInRadians cos.
+ y := distance * angleInRadians sin.
+ ^ x @ y
+
+ "
+ Point r:100 theta:0
+ "
+
+ "Modified: 2.4.1997 / 00:01:40 / cg"
+!
+
readFrom:aStringOrStream onError:exceptionBlock
"return the next Point from the (character-)stream aStream;
skipping all whitespace first; return the value of exceptionBlock,
@@ -687,16 +704,18 @@
!Point methodsFor:'polar coordinates'!
angle
- "return the receiver's angle (in radians) in a polar coordinate system.
+ "return the receiver's angle (in degrees) in a polar coordinate system.
(i.e. the angle of a vector from 0@0 to the receiver).
OBSOLETE ST/X interface; use theta for ST-80 compatibility."
- ^ self theta
+ ^ self theta radiansToDegrees
"
- (1@1) angle radiansToDegrees
- (2@1) angle radiansToDegrees
+ (1@1) angle
+ (2@1) angle
"
+
+ "Modified: 2.4.1997 / 00:02:17 / cg"
!
r
@@ -719,27 +738,33 @@
"return the receiver's angle (in radians) in a polar coordinate system.
(i.e. the angle of a vector from 0@0 to the receiver)"
- y < 0 ifTrue:[
- x < 0 ifTrue:[
- ^ 270 degreesToRadians - (y / x) arcTan
- ].
- x = 0 ifTrue:[
- ^ 180
- ].
- ^ 360 degreesToRadians - (y abs / x) arcTan
+ |theta t|
+
+ x = 0 ifTrue:[
+ y >= 0 ifTrue:[
+ ^ Float pi * 0.5
+ ].
+ ^ Float pi * 1.5.
].
+
+ t := y asFloat / x asFloat.
+ theta := t arcTan.
x < 0 ifTrue:[
- ^ 180 degreesToRadians - (y / x abs) arcTan
+ ^ theta +Float pi
].
- x = 0 ifTrue:[
- ^ 0
+ theta < 0 ifTrue:[
+ ^ theta + (Float pi * 2.0)
].
- ^ (y / x) arcTan
-
+ ^ theta.
"
- (1@1) theta radiansToDegrees
- (2@1) theta radiansToDegrees
+ (1@1) theta
+ (2@1) theta
+ (-2@1) theta
+ (-2@-1) theta
+ (0@-1) theta
"
+
+ "Modified: 2.4.1997 / 00:15:12 / cg"
! !
!Point methodsFor:'printing & storing'!
@@ -914,6 +939,6 @@
!Point class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.40 1997-01-25 16:28:47 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Point.st,v 1.41 1997-04-01 22:15:36 cg Exp $'
! !
Point initialize!