a curving construction method (not Bezier spline)

Blitz3D Forums/Blitz3D Programming/a curving construction method (not Bezier spline)

Raul(Posted 2010) [#1]
Not a conventional Bezier spline method, but can be useful for some applications.


;
; ALTERNATIVE CURVING CONSTRUCTION METHOD
;
; "how to get a curve using two lines segments"
;
; ralph.le.gall@...



Graphics 800,600,GraphicsDepth(),6


stp=20 ;<--you can change this "step" value


	x1#=150 : y1#=150 ;A starting place coords
	x2#=650 : y2#=450 ;B starting place coords

	Dim xyA#(stp,1) ;"segments line  steps"
	Dim xyB#(stp,1) ;"segments line  steps"
	Dim xyZ#(stp,1) ;"segments curve steps"

	;set green and yellow 3x3 dots..
	dotAB=CreateImage(3,3) : SetBuffer ImageBuffer(dotAB) : ClsColor   0,120,0 : Cls : MidHandle dotAB
	dotZ=CreateImage(3,3)  : SetBuffer ImageBuffer(dotZ)  : ClsColor 255,255,0 : Cls : MidHandle dotZ
	SetBuffer BackBuffer()


ClsColor 0,0,0

MoveMouse x2#,y1# ;move mouse to "orthogonal" place





;__________________________________________________________________________________________________________________

While KeyDown(1)=False

	xm#=MouseX() : ym#=MouseY()
	Cls

	;-------------------------------------------------------------------------------------------------
	;INFOS
	;-------------------------------------------------------------------------------------------------
	Color 120,120,120
	Text 10,10,"Left  click = place A"
	Text 10,25,"Right click = place B"
	Text xyA#(  0,0),xyA#(  0,1),"A"
	Text xyB#(stp,0),xyB#(stp,1),"B"
	;-------------------------------------------------------------------------------------------------


	;-------------------------------------------------------------------------------------------------
	;SET SEGMENTED LINES AND CURVE
	;-------------------------------------------------------------------------------------------------
	;construction lines coords..
	tmp_float#=(xm#-x1#)/stp : For i=0 To stp : xyA#(i,0)=x1#+((tmp_float#)*i) : Next
	tmp_float#=(ym#-y1#)/stp : For i=0 To stp : xyA#(i,1)=y1#+((tmp_float#)*i) : Next
	tmp_float#=(x2#-xm#)/stp : For i=0 To stp : xyB#(i,0)=xm#+((tmp_float#)*i) : Next
	tmp_float#=(y2#-ym#)/stp : For i=0 To stp : xyB#(i,1)=ym#+((tmp_float#)*i) : Next
	;curve coords (based on previous construction lines)..
	For i=0 To stp
	tmp_float#=(xyB#(i,0)-xyA#(i,0))/stp : xyZ#(i,0)=xyA#(i,0)+((tmp_float#)*i) ;X curve values
	tmp_float#=(xyB#(i,1)-xyA#(i,1))/stp : xyZ#(i,1)=xyA#(i,1)+((tmp_float#)*i) ;Y curve values
	Next
	;-------------------------------------------------------------------------------------------------


	;-------------------------------------------------------------------------------------------------
	;VISUAL ELEMENTS
	;-------------------------------------------------------------------------------------------------
	;green segments lines..
	Color 0,60,0 : For i=0 To stp : Line xyA#(i,0),xyA#(i,1),xyB#(i,0),xyB#(i,1) : Next
	;green and yellow 3x3 dots..
	For i=0 To stp
	DrawImage dotAB,xyA#(i,0),xyA#(i,1)		;green  dots (from A to mouse_XY)
	DrawImage dotAB,xyB#(i,0),xyB#(i,1)		;green  dots (from mouse_XY to B)
	DrawImage dotZ, xyZ#(i,0),xyZ#(i,1)		;yellow dots
	Next
	;yellow segments curve..
	Color 160,160,0 : For i=0 To stp-1 : Line xyZ#(i,0),xyZ#(i,1),xyZ#(i+1,0),xyZ#(i+1,1) : Next
	;-------------------------------------------------------------------------------------------------


	;-------------------------------------------------------------------------------------------------
	;PLACING DOTS A B
	;-------------------------------------------------------------------------------------------------
	If MouseDown(1) Then x1#=xm# : y1#=ym#
	If MouseDown(2) Then x2#=xm# : y2#=ym#
	;-------------------------------------------------------------------------------------------------


Flip False
Wend
;__________________________________________________________________________________________________________________

End



Oiduts Studios(Posted 2010) [#2]
You should put this in the code archives. Very cool


Nate the Great(Posted 2010) [#3]
cool, I have to say, me and my friends find it extremely entertaining to draw those grids on graph paper during math class when we have no free time :p

and um I think that is actually equivalent to a biezer routine...

see the quadratic section at the bottom:

http://en.wikipedia.org/wiki/B%C3%A9zier_curve


Raul(Posted 2010) [#4]
Thanks for comments !

I don't know how to proceed for code archives :(

The wikipedia link is really great :D
..the animations helps me to understand methodology !


Charrua(Posted 2010) [#5]
very good post

go to the code archives
http://blitzbasic.com/codearcs/codearcs.php
choose the category wher to post and then click on the link
Add to the "category choosen" code archives

Juan


Serpent(Posted 2010) [#6]
Very nice! Well coded - it's a simple line drawing method, but very effective!


Raul(Posted 2010) [#7]
Thanks for comments and informations.

I'll try to post other stuffs in athe code archives, if it can be useful for community.