Object subclass: #Cartesian
instanceVariableNames: 'x y'
Cartesian >> x
^x
Cartesian >> y
^y
Cartesian >> setX: newX y: newY
x := newX.
y := newY
Cartesian class >> newFrom: aPolar
^self new
setX: aPolar r * aPolar theta cos
y: aPolar r * aPolar theta sin; yourself
Cartesian class >> x: x y: y
^self new setX: x y: y; yourself
Object subclass: #Polar
instanceVariableNames: 'r theta'
Polar >> r
^r
Polar >> theta
^theta
Polar >> setR: newR theta: newTheta
r := newR.
theta := newTheta
Polar class >> newFrom: aCartesian
^self new
setR: (aCartesian x squared + aCartesian y squared) sqrt
theta: (aCartesian y arcTan: aCartesian x); yourself
Polar class >> r: r theta: theta
^self new setR: r theta: theta; yourself
| pos1 pos2 |
pos1 := pos2 := Polar r: 2 sqrt theta: Float pi / 4.
pos1 class.
pos1 become: (pos1 as: Cartesian).
pos1 class.
pos1 x.
pos1 y.
pos2 class.
pos1 become: (pos1 as: Polar).
pos1 class.
pos1 r.
pos1 theta / Float pi