Показать сообщение отдельно
Старый 18.10.2013, 23:11   #11
polopok
ПроЭктировщик
 
Регистрация: 17.07.2009
Сообщений: 182
Написано 51 полезных сообщений
(для 71 пользователей)
Ответ: некоторые изометрические демки

Рекомендую по теме:
http://habrahabr.ru/post/131931/
Спасибо ,давно лежит в закладках ...

продолжаем ...
проекция вектора на вектор .Статья донор Урок: базовые алгоритмы определения столкновений
код:
Type Vector
	Field lenght# ,vx#,vy#, dx# , dy# , rx#,ry# ,lx#,ly#
	Field px#[1] , py#[1] , selected = False , R ,G ,B
End Type
Global qx1#,qy1#

Graphics 800,600,32,2 
SetBuffer BackBuffer() 
ArialCyrFont = LoadFont ("Arial cyr",16)
SetFont ArialCyrFont 

v1.Vector = NewVector(150,100,200,150,0,0,100)
v2.Vector = NewVector(150,100,150,50,88,88,88)

ClsColor 255,255,255
While Not KeyHit(1) 
mx#  = MouseX() : my# = MouseY()
Cls 

For point.Vector = Each Vector
	If point <>Null Then 
	
		For p = 0 To 1
			Color 120,120,120
			If Dist(point\px[p] ,point\py[p],mx,my)<10 And MouseDown(1) 
				point\px[p] = mx 
				point\py[p] = my
				Oval mx-10,my-10, 20,20,0
				
			Else 
				Rect  point\px[p]-5,point\py[p]-5, 10,10,0	
			EndIf
		Next 
		If point\px[0]=point\px[1] And point\py[0]=point\py[1] Then 
			point\px[1]= point\px[1] +15
			point\py[1]= point\py[1] +15
		EndIf
	End If 
Next
		
		VectorUpdate(v1,v1\R ,v1\G ,v1\B)
		VectorUpdate(v2,v2\R ,v2\G ,v2\B)	
		dp# = projectVector(v1,v2\dx,v2\dy)


For point.Vector = Each Vector
	If point <>Null Then 		
		VectorDraw(point )
	End If 
Next		
	Color 0,255,0
	Line v2\px[0],v2\py[0] , v2\px[0] + v2\dx*dp	,v2\py[0]+ v2\dy*dp
	Oval v2\px[0]+v2\dX*dp -3,v2\py[0]+ v2\dY*dp -3,5,5,0
	Color 48,48,48
	Line v1\px[1],v1\py[1] , v2\px[0] + v2\dx*dp	,v2\py[0]+ v2\dy*dp

Text 220,20,"Навести мышь на квадрат и удерживая нажатой левую кнопку мыши,"
Text 220,40,"переместить стрелку мыши в новую позицию"
Text 220,60,"VectorDot: "+dp#
Flip 
Wend 
Delete Each Vector
FreeFont ArialCyrFont 
End
;[ end ]==============================================================================

Function projectVector#(a.Vector,dx#,dy#);
	; find dot product
	Local dp# =  a\vx*dx+a\vy*dy;
	Return dp#
End Function

Function FindXproject#(v.Vector,dp#)
	Return v\vx = dp#*v\dx;
End Function

Function FindYproject#(v.Vector,dp#)
	Return v\vy = dp#*v\dy;
End Function

Function VectorDraw(a.Vector  )
	Color 68,68,68
	Line a\px[0]+(-a\dx*1000 ) ,a\py[0]+(-a\dy*1000)  , a\px[0]+a\dx*1000   , a\py[0]+a\dy*1000 
	Color a\R,a\G,a\B
	Line a\px[0] ,a\py[0] , a\px[0]+ a\dX*a\lenght  , a\py[0]+a\dY*a\lenght 
	
	Oval a\px[0]+a\dX*a\lenght -2,a\py[0]+ a\dy*a\lenght -2,3,3,1
	
	Color 205,205,205
	Line a\px[0],a\py[0] , a\px[0]+ a\dX*5 , a\py[0]+a\dY*5	
	
	Oval a\px[0]+a\dX*a\lenght -3,a\py[0]+ a\dY*a\lenght -3,5,5,0
End Function	

Function NewVector.Vector(X1#=0,Y1#=0,X2#=0,Y2#=0, R= 255,G= 255,B= 255)
	Local v.Vector = New Vector
	v\vx = X2 -X1
	v\vy = Y2 -Y1
	v\lenght = VectorMagnitude#(v)
	; normalized
	v\dx = v\vx / v\lenght
	v\dy = v\vy / v\lenght
	; Right hand normal
	v\rx = -v\vy
	v\ry = v\vx
	; Left hand normal
	v\lx = v\vy
	v\ly = -v\vx
	; Coordinate Points
	v\px[0] =X1
	v\py[0] = Y1
	v\px[1] =X2
	v\py[1] = Y2
	; Vector colors 
	v\R = R
	v\G = G
	v\B = B
	Return v
End Function

Function VectorUpdate(v.Vector, R= 255,G= 255,B= 255)
	v\vx = v\px[1] -v\px[0]
	v\vy = v\py[1] -v\py[0]
	v\lenght = VectorMagnitude#(v)
	; normalized
	v\dx = v\vx / v\lenght
	v\dy = v\vy / v\lenght
	; Right hand normal
	v\rx = -v\vy
	v\ry = v\vx
	; Left hand normal
	v\lx = v\vy
	v\ly = -v\vx
	; Vector colors 
	v\R = R
	v\G = G
	v\B = B
End Function

Function VectorReverse(a.Vector)
	a\vX = -a\vX
	a\vY = -a\vY
End Function

Function VectorSubtract(a.Vector,b.Vector)
	a\vX =a\vX - b\vX
	a\vY =a\vY - b\vY
End Function

;Function VectorSum.Vector(a.Vector,b.Vector)
;	Return (a\vX+b\vX,a\vY+b\vY)
;End Function
	
;Function VectorDifference.Vector(a.Vector,b.Vector)
;	Return Vector(a\vX-b\vX,a\vY-b\vY)
;End Function
	
Function VectorMultiply(a.Vector,b.Vector)
	a\vX =a\vX * b\vX
	a\vY =a\vY * b\vY
End Function
	
Function VectorDivide(a.Vector,b.Vector)
	a\vX =a\vX / b\vX
	a\vY =a\vY / b\vY
End Function

Function VectorCross#(a.Vector,b.Vector)
	Return (a\vX*b\vY)-(a\vY*b\vX) 
End Function	


Function VectorDot#(a.Vector,b.Vector)
	Return (a\vX*b\vX) + (a\vY*b\vY)
End Function
	
Function VectorAngle#(a.Vector,b.Vector)
	Local d# = VectorDot(a,b)
	Local m# = VectorMagnitude(a)*VectorMagnitude(b)
	Return ACos(d#/m#)
End Function
	
Function VectorNormalize(a.Vector)
	Local m# = VectorMagnitude(a)
	If m<= 0.0001Then m=1
	a\vX = a\vX / m#
	a\vY = a\vY / m#
End Function
	
Function VectorMagnitude#(a.Vector)
	a\lenght = Sqr(a\vX*a\vX + a\vY*a\vY)
	Return a\lenght
End Function


;Function VectorProduct.Vector(a.Vector,b.Vector)
;	Return Vector(a\vX*b\vX,a\vY*b\vY)
;End Function
	
;Function VectorQuotient.Vector(a.Vector,b.Vector)
;	Return Vector(a\vX/b\vX,a\vY/b\vY)
;End Function

Function Dist#( X1#, Y1#, X2#, Y2# )
	Return Abs(( (X1 - X2)*(X1 - X2) + (Y1 - Y2)*(Y1 - Y2) )^0.5)
End Function
__________________
Мой проект здесь
(Offline)
 
Ответить с цитированием