sideOf: logic

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

sideOf: logic

Stéphane Ducasse
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
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

Reply | Threaded
Open this post in threaded view
|

Re: sideOf: logic

tbrunz
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

Reply | Threaded
Open this post in threaded view
|

Re: sideOf: logic

tbrunz
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

Reply | Threaded
Open this post in threaded view
|

Re: sideOf: logic

webwarrior
In reply to this post by Stéphane Ducasse
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

Reply | Threaded
Open this post in threaded view
|

Re: sideOf: logic

webwarrior
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