dy123
Jun 9 2007, 09:15 PM
I was wondering how to code a line or arrow to point in a direction ( N, NE, E, ..) based on a number in degrees (0-360)
Thanks for any help
CyberCow
Jun 10 2007, 07:29 AM
A while back, I modofied code for a
Round Analog Clock which could be modified to do the very thing you're asking about.
Some considerations will have to cope with changing the rotational pivot point from the end of a line control to the center of a line control. Or you could just invert the math for a second line control to give the appearance of a single solid line that rotates on it's center.
Allow me to find some time (and the old code) and see what may be derived.
CyberCow
Jun 10 2007, 10:09 AM
To what degree of precision does it need to be? In other words, does it need to point to one of 16 points; 1 of 32 points; one of 64 points; etc . . . ????
Attached is a simple one of 16 points . . . (It's in Access 97 and will convert nicely to anything above that. It's image based and does not employ vector math or line controls.)
CyberCow
Jun 10 2007, 11:04 AM
And here's one with 32 point precision . . . (also in Access 97)
dy123
Jun 10 2007, 11:41 AM
Thanks, thats exactly what I'm looking for.
cheekybuddha
Jun 10 2007, 01:30 PM
Hi,
Mark's solution requires the use of (quite a few!) images.
You can create a compass using a line control and some basic Trigonometry functions.
The line control has a height and width element which can equate to the two sides of a right angled triangle, with the pointer/needle being the hypotenuse.
Here is a quick example. It's not as pretty as Mark's but you can enter any integer degree value between 0 and 360.
hth,
d
CyberCow
Jun 10 2007, 02:12 PM
Hi D, I considered doing the trig thing too, but it would not gracefully allow the "line" to rotate on a centered pivot point, like the needle on a real compass. Making it look more like a clock-type compass than a needle compass. However, your trig'd code is pretty darn squeaky clean. Your's is also a much smaller file size. Nice work!
cheekybuddha
Jun 10 2007, 03:53 PM
Hi Mark,
Thanks for the kind words! I wondered about the 'tail' of the needle too. I thought about coding a couple of extra lines to form the 'point' of the arrow, but I thought I had better leave something for the OP to do.

Here's a modified version that uses another line as the reverse half of the needle. I just call the fSetPointer function again and add 180 degrees to the degrees passed to the main pointer.
I adjusted the fSetPointer function to accomodate degree values up to 540 (360 + 180) and to accept a length parameter so that it's easy to make the reverse end shorter so that it's more obvious.
I'm still leaving the coding of any arrow points to the OP though!
Regards,
d
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.