r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[gfx math] Graphics or geometry related math discussion

Maxim
15-Jan-2011
[134]
btw, the swap code is not related to Olde's last question, even if 
it is loosely related... its a gift function for anyone who needs 
to copy channels (usually manipulating alphas)
DideC
7-Feb-2011
[135x2]
Does anybody have done or begin a Box2d port in rebol ?
Is there something similar to this atan2 function in rebol (I guess 
no) :

http://msdn.microsoft.com/en-en/library/system.math.atan2%28v=vs.95%29.aspx
Andreas
7-Feb-2011
[137]
you have ARCTANGENT in rebol, atan2 should be easy to define based 
on it
Rebolek
8-Feb-2011
[138x2]
I made ATAN2 while ago, I try to find it.
can't find it right now, but it was based on http://en.wikipedia.org/wiki/Atan2
Steeve
8-Feb-2011
[140]
Found 2 versions in my scripts.
atan2: func [

 {Angle of the vector (0,0)-(x,y) with artangent y / x. The resulting 
 angle is extended to -pi,+pi}
	x y
][
	if x = 0 [x: 0.0000000001]
	add arctangent y / x pick [0 180] x > 0
]

atan2: func [x y][
	x: x + 0.00000001
	either x > 0 [
		arctangent y / x
	][
		180 + arctangent y / x
	]
]
BrianH
8-Feb-2011
[141]
How many zeros after the decimal point?
Steeve
8-Feb-2011
[142x2]
does that matter ?
I mean, you can round the result
BrianH
8-Feb-2011
[144]
I don't know, that's why it seemed worth asking. Don't know the reason 
for that line. If it is supposed to be close to 0 then 15 or 16 zeros 
would be the closest.
Steeve
8-Feb-2011
[145x2]
Found another one:
atan2: func [x y][
	x: x + 0.00000001
	x: either x > 0 [arctangent y / x][180 + arctangent y / x]
	360 + x // 360
]
Geez... How many time I rewrote that one ? 
:-)
the last one is weird...
Geomol
8-Feb-2011
[147]
:-) Make function libs!
BrianH
8-Feb-2011
[148]
Hard to adapt the formulas in the Wikipedia article, as they're in 
radians.
Geomol
8-Feb-2011
[149]
>> ? arctangent 
USAGE:
    ARCTANGENT value /radians

Maybe use /radians refinement?
BrianH
8-Feb-2011
[150]
Maybe atan2 should also have a /radians refinement.
Steeve
8-Feb-2011
[151x3]
I like that one too.

Project: func [

 {orthogonal projection of a point P on a line AB, return coordinates 
 [x y]}
	ax ay bx by px py
	/local sx sy ux uy ratio
][
	sx: bx - ax
	sy: by - ay
	ux: px - ax
	uy: py - ay
	ratio:  sx * ux + (sy * uy) / (sx * sx + (sy * sy))
	reuse [ratio * sx + ax  ratio * sy + ay]
]
I don't remember why i didn't use pair! as coordinates
Hmm, maybe to avoid path notations
BrianH
8-Feb-2011
[154]
Pairs in R3 are 32bit floats, decimals are 64bit.
Steeve
8-Feb-2011
[155x2]
I was for R2
and pairs are integers
BrianH
8-Feb-2011
[157x2]
And in R2 pairs are made up of integers.
AltME is a little slow for me today.
Steeve
8-Feb-2011
[159]
Ok, I know why I did it now ;-)
BrianH
8-Feb-2011
[160]
reuse?
Steeve
8-Feb-2011
[161x2]
reuse: funco [b][head reduce/into b clear []]
weird, I don't think anymore it was for R2
BrianH
8-Feb-2011
[163]
Not task-safe to reuse inline blocks like that.
Steeve
8-Feb-2011
[164x3]
And I don't like anymore that reuse too :-)
We should write an extension with such math/graphs functions
Maybe Brian you could start a wiki page for that purpose
BrianH
8-Feb-2011
[167]
Maybe it would be better for someone more familiar with and interested 
in mathematical issues to do so. Ladislav?
TomBon
10-Feb-2011
[168]
advise on how to colorize individual countries in a worldmap?
take a worldmap, draw background borders between the countries
and then floodfill the country via a central coordinate. 
is this a effective approach?
DideC
10-Feb-2011
[169x3]
Not enough probably as you might jave country border touching other 
border of the same countryy. Countries are not simple polygon !
My first though is to have a map (an image) of countries where each 
country has its own color (call it a color-map) and another map of 
the same size that you display (diplay-map).
Then you have a block of pairs [country-name country-color].
So like this you have a relationship in any sense.


Click the displayed map => find the corresponding pixel in the color-map 
=> find the country name in the block.

To know the edge of the country you want to fill, just find all the 
pixels of this same color in the color-map and poke the corresponding 
pixel on the diplay-map.
jave=have
TomBon
10-Feb-2011
[172:last]
yes, a precolorized map would make things simpler. thx didec...