Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance From Vector2D #24

Open
amcdnl opened this issue Feb 3, 2021 · 3 comments
Open

Distance From Vector2D #24

amcdnl opened this issue Feb 3, 2021 · 3 comments

Comments

@amcdnl
Copy link

amcdnl commented Feb 3, 2021

The Point2D has a distanceFrom function - it would be useful if the Vector2D has a similar function.

Example: I have a SVG rect and a mouse event and I want to know the distance from any point in the rect.

@thelonious
Copy link
Owner

Hi @amcdnl,

I may be misunderstanding what you're looking for, so I want to confirm...

It sounds like you're converting the current mouse position and a corner on the rectangle to a vector. To find the distance between those two points using the vector, you can get the vector's length. Would that work for you?

@lysz210
Copy link
Contributor

lysz210 commented Feb 3, 2021

@amcdnl I think you're using vectors instead of point. Use points to map mouse pointer positions. Maybe I'm wrong but I think of vector as what you need to move p1 to p2. For example P1(0,0), if i apply v(1,2) to p1 it results in p2(1,2), then if I apply v2(1,1) to p2 it results in p3(2,3) so there isn't a distance between 2 vector because it's a third v3(2,3). This is because if apply v3 to p1 I'll get p3.

@amcdnl
Copy link
Author

amcdnl commented Feb 3, 2021

This is what I was looking for ( I wrote this myself ) - https://github.com/reaviz/reaflow/blob/master/src/helpers/useProximity.ts#L93-L113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants