tbrosman / hxmath

A math library for Haxe.
MIT License
92 stars 10 forks source link

Distance between two points #4

Closed tiagolr closed 10 years ago

tiagolr commented 10 years ago

Hey, this is very handy to have in a unified math lib, also other trigonometric operations,

you can get a lot of useful game for maths (including source code) here: https://github.com/HaxeFlixel/flixel/tree/dev/flixel/math , sometimes it uses flixel structures like FlxPoint, and they only work for 2D, however they can be adapted i think.

thanks a lot even more if adding more methods to this lib ^^

tbrosman commented 10 years ago

Distance is pretty simple as-is. For example, if you have two Vector(2,3,4)'s and you want to know the distance between them:

(a - b).length

There's no dedicated "distance" function as I didn't want to make a differentiation between points and vectors (mainly out of simplicity).

I know Flixel bundles a lot of functions into their math library. Some of them seem useful, but out of place (why does FlxPoint have ceil/floor? those are scalar functions) and other seem... strange. I'm trying to find a good balance and put things in the right place.

Given that constraint, what functions/concepts/structures would you like to see added? One thing I am considering a coordinate frame object similar to how Flixel lets you transform between frames using two Rects.

tiagolr commented 10 years ago

Nice, youre right, i feel a bit dumb about maths with your answer witch is good, i trust looking at those math classes you can figure what can be added that adds value.

Well here are a couple of suggestions i think may be useful.

basic:

more complex:

other:

I can think of those now, some of them may be too basic to add, or may be easily done using vectors math, the geometry intersections would be nice tho.

Some geometry algorithms may also be found here: https://github.com/fponticelli/thx Including geometry, easing functions and what not.

Again thanks for this lib, and keep it this quality ;)

tbrosman commented 10 years ago

The geometry predicates I am planning on adding. That's kindof a future goal though; for now I plan on focusing on scalar/vector/matrix math.

Random number between a and b may or may not be in scope. I have a pseudo-random number xor-shift-based generator I'm thinking about porting, but it depends on priorities.

Angle between two Vectors is definitely in scope; I will open a bug for that. (Issue #5)

Rotate around point (pivot) is in scope as well (as something to add to Matrix2x2) and I will open a bug for that as well. (Issue #6)

tbrosman commented 10 years ago

I'm closing this; I will continue to add features and hopefully get to geometry features sometime in the near future. Thanks again for the suggestions and feel free to email me if you have any other ideas!