suggestion: math.mod

BlitzMax Forums/BlitzMax Module Tweaks/suggestion: math.mod

Red(Posted 2005) [#1]
- GetDistance
- GetAngle


Takuan(Posted 2005) [#2]
splines calculating stuff would be handy too...


Perturbatio(Posted 2005) [#3]
here's a start:
Rem
bbdoc: returns the distance between two points in 2D space
about: return value is an absolute float
EndRem
Function GetDistance2D:Float(X1:Float, Y1:Float, X2:Float, Y2:Float)
	Local l1:float = Abs(x1-x2)
	Local l2:float = Abs(y1-y2)
	Return Sqr((l1*l1)+(l2*l2))
End Function

Rem
bbdoc: returns the distance between two points in 3D space
about: return value is an absolute float
EndRem
Function GetDistance3D:Float(X1:Float, Y1:Float, Z1:Float, X2:Float, Y2:Float, Z2:Float)
	Local l1:float = Abs(x1-x2)
	Local l2:float = Abs(y1-y2)
	Local l3:float = Abs(z1-z2)
	Return Sqr((l1*l1)+(l2*l2)+(l3*l3))
End Function




klepto2(Posted 2005) [#4]
And here is something to get the 2d angle:


Rem
bbdoc: returns an angle between 0 and 360 degrees
about: return value is an Float
EndRem

Function GetAngle2D:Float(X1:Float,Y1:Float,X2:Float,Y2:Float)
         local dx# = x2 - x1
         local dy# = y2 - y1
         Return ATAN2(dy#,dx#)+360) MOD 360
End Function



Beaker(Posted 2005) [#5]
Pert - why are you NOT using Floats/Doubles for your functions local variables?


N(Posted 2005) [#6]
Friendly-friendly math code for peoples.




Garred(Posted 2005) [#7]
Maybe this is wrong:
Type Quat
...
	Method MultiplyQuat:Quat( i:Quat )
		Local r:Quat = New Quat
		
		r.w = w*i.w - x*i.x - y*i.y - z*i.z
		r.w = w*i.x - x*i.w - y*i.z - z*i.y
		r.w = w*i.y - y*i.w - z*i.x - x*i.z
		r.w = w*i.z - z*i.w - x*i.y - y*i.x
		
		Return r
	End Method
...
End Type
Why to redefine the same variable 4 times?


N(Posted 2005) [#8]
Woops, forgot to write all the diferent stuff in :P


Red(Posted 2005) [#9]
Thx dude

I hope they will be official commands