View Full Version : problem with ray in an array of points

03-09-2005, 09:50 AM
See in the script below.
So if I change the lattice (see dir2d), and i.e. y is 0.5 or -0.5 instead of 1 and -1, ray will jump previous point B and new point A will not coincide, and I have tried but I cannot figure out how to change point A values (I guess there is the problem) to solve this stuff that is causing me headaches
If I change the random coordinates dir2d to 1 unit interval everything works, if one of the 4 position in dir2d is i.e 0.5 when the spline is traced a gap is shown.

I was told that multiplying dir for a constant i.e. v=0.5 I could change pos in the ray, I have tried in different vays but it did not work and is crucial that dir2d can have not just 1 unit jump.
Please help me I have to solve this for my uni project!
Thanks a lot Tim.
-- fns
fn drawLineBetweenTwoPoints pointA pointB col=
ss = SplineShape pos:pointA renderable:true thickness:0.05 wirecolor:col
addNewSpline ss
addKnot ss 1 #corner #line PointA
addKnot ss 1 #corner #line PointB
updateShape ss

function new2DDir=
return dirArr[random 1 dirArr.count]

--function new2DDir=
--return dirArr[random 1 dirArr.count]

function plot steps trace:false drawMode:1=
-- utility
if trace then clearlistener()
delete objects
r=ray [0,0,0] [1,0,0]

-- code
for i = 1 to steps do
-- feedback
local pc=((i as float/steps)*100) as integer
displaytempprompt ("Processing: " + pc as string +"% done") 1

-- color
local c=(i as float/steps)*255
col=color c c c 255

-- new ray
dir= new2DDir()
--v= ( if abs dir.x == 0.5 then 0.5 else 1) -- I mean IT SHOULD BE SOMETHING LIKE THAT!
pointA= rayArr[rayArr.count].pos + (rayArr[rayArr.count].dir)--*v)
pointB= pointA+dir
r= ray pointA dir

-- test that this ray / dir hasn't been used yet
-- one of two modes:
-- 1: don't use same space and direction
-- 2: don't use same space
if drawMode==1 then
for test in rayArr do if (r.pos==test.pos AND r.dir==test.dir) then (draw=false;continue)
for test in rayArr do if (r.pos+r.dir==test.pos) then (draw=false;continue)

-- draw the line
if draw then
drawLineBetweenTwoPoints pointA pointB col
append rayArr r
-- trace result
if trace then format "% %\n" pointA pointB

-- zoom
max zoomext sel all
messagebox("Number of splines" + rayArr.count as String) beep:false

-- code
plot 200 drawMode:0
print rayArr

CGTalk Moderation
03-09-2005, 09:50 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.