#### Archived

This topic is now archived and is closed to further replies.

# point on a bezier

This topic is 5349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How could I get the coordinates of a point on a bezier line, given a value from 0 to 1? (0 is one endpoint, 1 being the other end.)

##### Share on other sites
What kind of Bezier curve fitting routine are you using? Most derivations give, as output, parametric equations that do exactly what you''re asking.

##### Share on other sites
Here''s what I''m doing right now. (its darkbasic code)
Circle travels back and forth over the line.

the increments aren''t equal, so the circle moves at inconsistent speeds.

sync rate 0sync onsw = screen width()sh = screen height() - 80speed# = 0.001randomize timer()x1 = rnd(sw)y1 = rnd(sh) + 16x2 = rnd(sw)y2 = rnd(sh) + 16c1x = rnd(sw)c1y = rnd(sh) + 16c2x = rnd(sw)c2y = rnd(sh) + 16mousemode = 0control = 0set text font "Arial"set text size 16repeat   cls   if inkey$()="a" mousemode = 1 control = 1 endif if inkey$()="b"      mousemode = 1      control = 2   endif   if inkey$()="1" mousemode = 1 control = 3 endif if inkey$()="2"      mousemode = 1      control = 4   endif   if mouseclick()=1      mousemode = 0   endif   if mousemode = 1      select control         case 1            x1 = mousex()            y1 = mousey()         endcase         case 2            x2 = mousex()            y2 = mousey()         endcase         case 3            c1x = mousex()            c1y = mousey()         endcase         case 4            c2x = mousex()            c2y = mousey()         endcase      endselect   endif   text 0,0,"A: " + str$(x1) + "x " + str$(y1) + "y"   text 0,20,"B: " + str$(x2) + "x " + str$(y2) + "y"   text 0,40,"C1: " + str$(c1x) + "x " + str$(c1y) + "y"   text 0,60,"C2: " + str$(c2x) + "x " + str$(c2y) + "y"   text 0,80, str\$(t#)   center text screen width()/2,screen height()-20,"Bezier Curve - Press A/B/1/2 to move the points. Left Mouse to set"   if thing = 1      ttt# = ttt# + speed#      if ttt# >= 1 then thing=0   endif   if thing = 0      ttt# = ttt# - speed#      if ttt# <= 0 then ttt# = 0: thing=1   endif   Bezier(x1, y1, x2, y2, c1x, c1y, c2x, c2y, ttt#)   syncuntil escapekey()endfunction Bezier(x1, y1, x2, y2, c1x, c1y, c2x, c2y, t#)   x as float   y as float   cx as float   bx as float   ax as float   cy as float   by as float   ay as float   x = x1   y = y1   cx = 3 * (c1x - x1)   bx = 3 * (c2x - c1x) - cx   ax = x2 - x1 - cx - bx   cy = 3 * (c1y - y1)   by = 3 * (c2y - c1y) - cy   ay = y2 - y1 - cy - by   text x1,y1,"a"   text x2,y2,"b"   text c1x,c1y,"c1"   text c2x,c2y,"c2"   x = ((ax * t# + bx) * t# + cx) * t# + x1   y = ((ay * t# + by) * t# + cy) * t# + y1   ink rgb(255,0,0),0   circle x, y, 10   ink rgb(255,255,255), 0   for t# = 0 to 1.05 step .05      x = ((ax * t# + bx) * t# + cx) * t# + x1      y = ((ay * t# + by) * t# + cy) * t# + y1        First time through?      if t# = 0         oldx = x         oldy = y      endif      line oldx, oldy, x, y      oldx = x      oldy = y   next t#endfunction `

##### Share on other sites
What do you suppose the lines

x = ((ax * t# + bx) * t# + cx) * t# + x1
y = ((ay * t# + by) * t# + cy) * t# + y1

are doing?

Stevie

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633375
• Total Posts
3011555
• ### Who's Online (See full list)

There are no registered users currently online

×