sideOf: logic

SD
Stéphane Ducasse
Wed, Sep 9, 2020 1:43 PM

Hi all

we have the following method on point and I do not get

why

(0@0) sideOf: (100@100)

#center

sideOf: otherPoint
"Returns #left, #right or #center if the otherPoint lies to the left, right or on the line given by the vector from 0@0 to self"

| side |
side := (self crossProduct: otherPoint) sign.
^ { #right . #center . #left } at: side + 2

Stéphane Ducasse
http://stephane.ducasse.free.fr / http://www.pharo.org
03 59 35 87 52
Assistant: Aurore Dalle
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley,
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France

Hi all we have the following method on point and I do not get why (0@0) sideOf: (100@100) >>> #center sideOf: otherPoint "Returns #left, #right or #center if the otherPoint lies to the left, right or on the line given by the vector from 0@0 to self" | side | side := (self crossProduct: otherPoint) sign. ^ { #right . #center . #left } at: side + 2 -------------------------------------------- Stéphane Ducasse http://stephane.ducasse.free.fr / http://www.pharo.org 03 59 35 87 52 Assistant: Aurore Dalle FAX 03 59 57 78 50 TEL 03 59 35 86 16 S. Ducasse - Inria 40, avenue Halley, Parc Scientifique de la Haute Borne, Bât.A, Park Plaza Villeneuve d'Ascq 59650 France
T
tbrunz
Wed, Sep 9, 2020 3:57 PM

I'm not sure, but I suspect this is a helpful method for things in analytic
geometry.

I.e., if you have a ray and a point, it would allow you to determine the
direction to move for the shortest path (in polar coordinates, for example).

-t

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

I'm not sure, but I suspect this is a helpful method for things in analytic geometry. I.e., if you have a ray and a point, it would allow you to determine the direction to move for the shortest path (in polar coordinates, for example). -t -- Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
T
tbrunz
Wed, Sep 9, 2020 5:15 PM

It just occurred to me: If you have a graphic element, such as a triangle or
rectangle, etc., and you want to know if a point lies inside it or outside
it, you would want a method such as this one.

But I think you would need to apply it relative to a vertex of the polygon
in question, since it assumes a ray starting at (0@0) to a given point
(i.e., an adjoining vertex).

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

It just occurred to me: If you have a graphic element, such as a triangle or rectangle, etc., and you want to know if a point lies inside it or outside it, you would want a method such as this one. But I think you would need to apply it relative to a vertex of the polygon in question, since it assumes a ray starting at (0@0) to a given point (i.e., an adjoining vertex). -- Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
W
webwarrior
Fri, Sep 11, 2020 8:42 PM

Stéphane Ducasse wrote

Hi all

we have the following method on point and I do not get

why

(0@0) sideOf: (100@100)

#center

sideOf: otherPoint
"Returns #left, #right or #center if the otherPoint lies to the left,
right or on the line given by the vector from 0@0 to self"

| side |
side := (self crossProduct: otherPoint) sign.
^ { #right . #center . #left } at: side + 2

Segment from 0@0 (origin) to 0@0 (receiver) has 0 length, so its direction
is undefined. Therefore you cannot expect meaningful answer here.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Stéphane Ducasse wrote > Hi all > > we have the following method on point and I do not get > > why > > (0@0) sideOf: (100@100) > >>> #center > > > > sideOf: otherPoint > "Returns #left, #right or #center if the otherPoint lies to the left, > right or on the line given by the vector from 0@0 to self" > > > | side | > side := (self crossProduct: otherPoint) sign. > ^ { #right . #center . #left } at: side + 2 Segment from 0@0 (origin) to 0@0 (receiver) has 0 length, so its direction is undefined. Therefore you cannot expect meaningful answer here. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html
W
webwarrior
Sat, Sep 12, 2020 5:05 PM

Better explanation:

Side is determined with respect to line that goes through 2 points: origin
and receiver.
If receiver = origin, you only have 1 point -> infinitely many lines exist
that go through 1 point -> cannot determine side.

--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Better explanation: Side is determined with respect to line that goes through 2 points: origin and receiver. If receiver = origin, you only have 1 point -> infinitely many lines exist that go through 1 point -> cannot determine side. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html