Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Draw an arrow
Message
De
19/06/2002 17:35:46
 
 
À
18/06/2002 09:29:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Divers
Thread ID:
00669490
Message ID:
00670328
Vues:
27
>>>>Hi,
>>>>
>>>>I need to draw an arrow on a form from x1, y1 to x2, y2. I know how to draw the line, but the arrow part is a riddle to me. I guess it requires a formula and/or some special functions.
>>>>
>>>>Any idea?
>>>
>>>I agree that three lines would probably do the job. Tell me if you want help with the math part (trigonometry). Although I haven't figured it out yet, I think it should be easy.
>>>
>>>Hilmar.
>>
>>Hi Hilmar,
>>
>>(BTW, thanks for your reply on 'Public, Private, Global' :)
>>
>>Some help would be appreciated. Trigonometry is not my specialty.
>
>This method added to the form may help, I called mine arrow. It allowed drawing a line with an optional arrowhead at either end, pointing inwards or outwards dependant on the length or angle of the arrow head.
>
>
>***************************************************************
>* x1, y1 define start point of arrow (p1)
>* x2, y2 define end point of arrow (p2)
>* hdlen is length of arrow head
>* hdang is angle of arrow head from straight line, in degrees
>* p1h, p2h define if arrow head should at p1 & p2 respectively
>* for reversed arrow heads make hdlen negative OR hdang > 90
>***************************************************************
>	lparameters x1, y1, x2, y2, hdlen, hdang, p1h, p2h
>	local ang1r, hdar, nxa, nya, nxb, nyb
>	local xdif, ydif, xsum, ysum
>
>		* convert angle of arrow head to radians
>	hdar = DTOR( hdang )
>		* calculate slope of main line
>	ang1r = ATAN( (y2-y1)/(x2-x1) )
>
>		* calculate change in x & y positions due difference between above angles
>	xdif = hdlen * COS( ang1r - hdar )
>	ydif = hdlen * SIN( ang1r - hdar )
>		* calculate change in x & y positions due sum of above angles
>	xsum = hdlen * COS( ang1r + hdar )
>	ysum = hdlen * SIN( ang1r + hdar )
>
>		* draw main line
>	thisform.Line( x1, y1, x2, y2 )
>
>		* if arrow head required at p1
>	if p1h
>			* if drawing left to right or vertical than difference in lengths
>			* should be added, otherwise subtracted
>		if x2 >= x1
>			nxa = x1 + xdif
>			nya = y1 + ydif
>			nxb = x1 + xsum
>			nyb = y1 + ysum
>		else
>			nxa = x1 - xdif
>			nya = y1 - ydif
>			nxb = x1 - xsum
>			nyb = y1 - ysum
>		endif
>			* draw p1 arrow heads
>		thisform.Line( x1, y1, nxa, nya )
>		thisform.Line( x1, y1, nxb, nyb )
>	endif
>
>		* if arrow head required at p2
>	if p2h	
>			* if drawing left to right or vertical than difference in lengths
>			* should be subtracted, otherwise added
>		if x2 >= x1
>			nxa = x2 - xdif
>			nya = y2 - ydif
>			nxb = x2 - xsum
>			nyb = y2 - ysum
>		else
>			nxa = x2 + xdif
>			nya = y2 + ydif
>			nxb = x2 + xsum
>			nyb = y2 + ysum
>		endif
>			* draw p2 arrow heads
>		thisform.Line( x2, y2, nxa, nya )
>		thisform.Line( x2, y2, nxb, nyb )
>	endif
>
>
>if it needs clarify, please feel free to ask.

Ha! It worked right away! Great. Thanks!
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform