I have been working on some code for my 3d-world ans i made a simple 2d version of the problem
Don't seem to get it right and it's more complicated then i did think.
I have a part working function but i need some help with the yellow line insite the function crosspoint
it needs to calculate the center value so the intersection point become right and circles end up on the yellow line.
So only the center value needs to be calculated inside the function (see picture)
http://ac1.servegame.com:88/image/Crosspointdata.PNG
Not really difficult juist drives me crazy.
help will be appreciated.
When it works i will share my 3d-code for it at viewtopic.php?f=8&t=27809&p=263713#p263713
Code: Select all
declare function my_line(vertex1 as single, vertex2 as single, noise1 as single, noise2 as single, div_noise as ubyte) as single 'my linear interpolation vertex (vector, vector, noise1, noise2, isovalue?)
type crosspointdata
dim as single D1
dim as single D2
dim as ubyte crossed
dim as single div
end type
function crosspoint(p1 as single, p2 as single, p3 as single, p4 as single, div_noise as ubyte) as single
static as crosspointdata w(3) ' please load points clockwise
W(0).d1 = p1: W(0).d2 = p2: W(0).crossed = 0
W(1).d1 = p2: W(1).d2 = p3: W(1).crossed = 0
W(2).d1 = p4: W(2).d2 = p3: W(2).crossed = 0
W(3).d1 = p1: W(3).d2 = p4: W(3).crossed = 0
for i as ubyte = 0 to 3
if W(i).d1 < div_noise andalso W(i).d2 >= div_noise then W(i).crossed = 1
if W(i).d1 >= div_noise andalso W(i).d2 < div_noise then W(i).crossed = 1
next
if W(0).crossed + W(1).crossed + W(2).crossed + W(3).crossed < 1 then return -1: exit function
for i as ubyte = 0 to 3
if W(i).crossed=1 then
W(i).div = my_line(-1, 1, W(i).d1, W(i).d2, div_noise)
end if
next
if W(0).crossed=1 then circle(W(0).div,-1),.02:draw string (W(0).div,-1.15),"W0=" & str(W(0).div)
if W(1).crossed=1 then circle(1,W(1).div), .02:draw string (1.25, W(1).div),"W1=" & str(W(1).div)
if W(2).crossed=1 then circle(W(2).div,1), .02:draw string (W(2).div, 1.15),"W2=" & str(W(2).div)
if W(3).crossed=1 then circle(-1,W(3).div),.02:draw string (-1.25,W(3).div),"W3=" & str(W(3).div)
for tmp as ubyte = 0 to 2
'calcualate cross points 2>div_noise 2<div_noise
if W(0).crossed=1 andalso W(2).crossed=1 andalso W(1).crossed=0 andalso W(3).crossed=0 then
line (W(2).div,1)-(W(0).div,-1)
var n1 = (W(2).div - W(0).div)/2
var n2 = ((W(2).div)) - n1
circle(n2,0), .02 'the right point
'print n1, n2
if n2<0 then
var n4 = ((W(3).d1 + W(3).d2)/2)
var n5 = (div_noise-n4) / (1+n2)
return n4+n5
else
var n4 = ((W(1).d1 + W(1).d2)/2)
var n5 = (div_noise-n4) / (1-n2)
return n4+n5
end if
end if
'calculate 1 corner state
if W(0).crossed=1 andalso W(1).crossed=1 andalso W(2).crossed=0 andalso W(3).crossed=0 then
line (1,W(1).div)-(W(0).div,-1)
var n1 = (W(2).div - W(0).div)/2
var n2 = ((W(2).div)) - n1
print n1, n2,
circle(n2,0), .02 'the right point
return 128 +((TIMER*100) MOD 1000)/100
end if
'calcualate conner points 2>div_noise 2<div_noise
print "1 rotation"
swap W(0),W(1)
swap W(1),W(2)
swap W(2),W(3)
next
'beep
return -1
end function
Screenres 1440,900,32
Window (-2,1.3)-(2,-1.3)
DO
CLS
dim as single array(-1 to 1, -1 to 1) = {{126,0,115},{0,0,0},{140,0,132}}
dim as single avg(-1 to 1, -1 to 1)
array(1,1) += ((TIMER*100) MOD 500)/100
'draw grid
line (0,1)-(0,-1),rgb(63,63,63)
line (1,0)-(-1,0),rgb(63,63,63)
line (-1,-1)-(1,-1),rgb(127,127,127)
line (-1,1)-(1,1),rgb(127,127,127)
line (-1,1)-(-1,-1),rgb(127,127,127)
line (1,1)-(1,-1),rgb(127,127,127)
'draw array values
draw string (-1.1,-1.1),"P1=" & str(array(-1,-1))
draw string (-1.1,-0.05),"P2=" & str(array(-1,0))
draw string (-1.1,1.1), "P3=" & str(array(-1,1))
draw string (0,-1.1), "P4=" & str(array(0,-1))
draw string (0,-0.05), "P5=" & str(array(0,0))
draw string (0,1.1) , "P6=" & str(array(0,1))
draw string (1.1,-1.1), "P7=" & str(array(1,-1))
draw string (1.1,-0.05),"P8=" & str(array(1,0))
draw string (1.1,1.1) , "P9=" & str(array(1,1))
color rgb(255,0,0)
avg(0,0)=crosspoint(array(-1,-1),array(1,-1),array(1,1),array(-1,1),127)
draw string (0,-.15) , "red=" & str(avg(0,0))
avg(-1,0)= (array(-1,-1)+array(-1,1))/2
avg(1,0)= (array(1,-1)+array(1,1))/2
avg(0,-1)= (array(1,-1)+array(-1,-1))/2
avg(0,1)= (array(-1,1)+array(1,1))/2
avg(-1,-1)= array(-1,-1)
avg(-1,1)= array(-1,1)
avg(1,-1)= array(1,-1)
avg(1,1)= array(1,1)
color rgb(127,0,0)
draw string (-1.15,-1.15),"P1=" & str(avg(-1,-1))
draw string (-1.15,-0.1), "P2=" & str(avg(-1,0))
draw string (-1.15,1.15), "P3=" & str(avg(-1,1))
draw string (0,-1.15), "P4=" & str(avg(0,-1))
draw string (0,-0.1), "AVG=" & str((avg(-1,0)+avg(1,0))/2)
draw string (0,1.15) , "P6=" & str(avg(0,1))
draw string (1.15,-1.15), "P7=" & str(avg(1,-1))
draw string (1.15,-0.1), "P8=" & str(avg(1,0))
draw string (1.15,1.15) , "P9=" & str(avg(1,1))
circle (my_line(-1,0,avg(-1,0),avg(0,0),127),0),.01 ,rgb(255,255,255)
'circle (my_line(1,0,avg(1,0),avg(0,0),127),0),.01, rgb(255,255,255)
circle (0, my_line(1,0,avg(0,1),avg(0,0),127)),.01, rgb(255,255,255)
'circle (0, my_line(-1,0,avg(0,-1),avg(0,0),127)),.01 ,rgb(255,255,255)
'' state 2 coner1 yellow
array(1,1)=122
array(-1,-1)=123
array(1,1) -= ((TIMER*100) MOD 500)/100
color rgb(255,255,0)
avg(0,0)=crosspoint(array(-1,-1),array(1,-1),array(1,1),array(-1,1),127)
if avg(0,0) = -99 then beep: avg(0,0) = 126
draw string (-.2,-.15) , "?=" & str(avg(0,0))
avg(-1,0)= (array(-1,-1)+array(-1,1))/2
avg(1,0)= (array(1,-1)+array(1,1))/2
avg(0,-1)= (array(1,-1)+array(-1,-1))/2
avg(0,1)= (array(-1,1)+array(1,1))/2
avg(-1,-1)= array(-1,-1)
avg(-1,1)= array(-1,1)
avg(1,-1)= array(1,-1)
avg(1,1)= array(1,1)
color rgb(127,127,0)
draw string (-1.2,-1.2),"P1=" & str(avg(-1,-1))
draw string (-1.2,-0.15),"P2=" & str(avg(-1,0))
draw string (-1.2,1.2), "P3=" & str(avg(-1,1))
draw string (0,-1.2), "P4=" & str(avg(0,-1))
draw string (-.2,-0.1), "AVG=" & str((avg(-1,0)+avg(1,0))/2)
draw string (0,1.2) , "P6=" & str(avg(0,1))
draw string (1.2,-1.2), "P7=" & str(avg(1,-1))
draw string (1.2,-0.15), "P8=" & str(avg(1,0))
draw string (1.2,1.2) , "P9=" & str(avg(1,1))
var yellow1 = my_line(1,0,avg(1,0),avg(0,0),127)
var yellow2 = my_line(-1,0,avg(0,-1),avg(0,0),127)
'circle (my_line(-1,0,avg(-1,0),avg(0,0),127),0),.01 ',rgb(255,255,255)
circle (yellow1,0),.01 ',rgb(255,255,255)
'circle (0, my_line(1,0,avg(0,1),avg(0,0),127)),.01 ',rgb(255,255,255)
circle (0,yellow2 ),.01 ',rgb(255,255,255)
sleep 10
LOOP WHILE INKEY$ = ""
function my_line(vertex1 as single, vertex2 as single, noise1 as single, noise2 as single, isovalue as ubyte) as single 'my linear interpolation vertex (vector, vector, noise1, noise2, isovalue?)
Static as single liv
Static as single div_noise1: div_noise1 = abs(noise1 - isovalue)
Static as single lengte: lengte = div_noise1 + abs(noise2 - isovalue)
Static as single diff1: diff1 = (lengte - div_noise1) * (1 / lengte)
Static as single diff2: diff2 = 1-diff1
liv = ((vertex1 * diff1) + (vertex2 * diff2))
return liv
end function