Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:14 13 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Is this possible

     Page 1 of 2    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 10:38am 04 Dec 2020
Copy link to clipboard 
Print this post

I've been trying to figure out if it's possible to get something like this without the fancy star in the middle without using an image
I mean a Circle or 2 Circles with the lines around it and the letters
I've been using this
but I'd like to do it without using an image as I need it to be able to be used on a couple of different resolution displays

I know how to do the circles but I have no idea if you can make the marks around the outside or not and put the direction letters in place using mmbasic
Edited 2020-12-04 20:40 by lew247
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 374
Posted: 11:15am 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  I've been trying to figure out if it's possible to get something like this without the fancy star in the middle without using an image
I mean a Circle or 2 Circles with the lines around it and the letters
I've been using this
but I'd like to do it without using an image as I need it to be able to be used on a couple of different resolution displays

I know how to do the circles but I have no idea if you can make the marks around the outside or not and put the direction letters in place using mmbasic


Do you want the direction labels to change to show something or is N always vertically at the end?

Presumably a TEXT x,y, "N"
            TEXT x,y, "E"

etc etc would work.  You just need the x,y cordinates...

Nim
Entropy is not what it used to be
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 11:30am 04 Dec 2020
Copy link to clipboard 
Print this post

Could you use the image rotate command? Seems like it might work, with a bit of experimentation.

Steve
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 11:33am 04 Dec 2020
Copy link to clipboard 
Print this post

To continue...with the lines...thats just trigonometry....well, it would take me some time to figure...but should work.

Steve
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1636
Posted: 12:01pm 04 Dec 2020
Copy link to clipboard 
Print this post

Could you use different images to suit the different resolutions?

Bill
Keep safe. Live long and prosper.
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:01pm 04 Dec 2020
Copy link to clipboard 
Print this post

No, I'd rather not have lots of images and choose depending on screen resolution
It would be simpler if it could be done in code but if that's the only way it can be done then so be it. I was just hoping it could be done in code

The Compass has to stay static

I have a triangle pointer that moves
Edited 2020-12-04 23:03 by lew247
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 06:28pm 04 Dec 2020
Copy link to clipboard 
Print this post

It looks like you want is to find the x and y point from any given angle.

The formula for finding any point on a circle is x=cos(angle)*radius and  y=sin(angle)*radius




Lets call a variable "a" and make it our angle. Make another variable "r" and this is the radius of the circle you want. (in the above diagram "t" is the angle and it has a radius of 1). To find the X and Y for any point on that circle of radius r, you need to provide the angle a.

The formula for this is

x=cos(a)*r
y=sin(a)*r


The only real gotcha here is that by default BASIC uses Radians instead of Degrees for it's angles. You can make it use Degrees by adding


option angle degreees


at the top of the program. Or alternatively you could convert angle "a" in to Radians.

So the following program will draw a series of lines from the center to the outer points in a circle


option angle degrees
for a=0 to 360
 x=cos(a)*100
 y=sin(a)*100
 line 200,200,200+x,200+y
next a


Note: Because the x and the y can go negative and 0,0 is the center of the circle I have added 200 to all of the x and y values so that the lines appear on the screen (otherwise you would only see a quarter of the circle at the top left of the screen).



This is the basic formula you need for drawing anything in a circle. So to get to your compass, we are going to do three things.

First off, we are drawing a line for every degree, I suspect you only want a line every 5 degrees so we add a "STEP" command to the for loop to make it step up in multiples of 5

for a=0 to 360 step 5


Next we don't want to draw the line from the center, so we could use the formula to calculate the points on two circles. One with a radius of 90 and one with  radius of 100 and draw a line between those points (instead of from the center to the outer circle).


x1=cos(a)*90
y1=sin(a)*90
x2=cos(a)*100
y2=sin(a)*100
line x1+200,y1+200,x2+200,y2+200


This gives you the outer ticks.

Finally you want to be able to put text next to some of them. You can use the same formula to find the x and y locations of the text. This time we will make the radius of the "text" circle 110. Normally text is positioned by the top left point. We need to center them so that the point we are using from our 110 radius circle is actually at the center of the text. We can use the "TEXT" for this, with options CM to specify center and middle alignment.

There's probably a neater way to do this, but to keep it simple

x3=cos(a)*110 + 200
y3=sin(a)*110 + 200
if a=0 then text x3,y3,"N",CM
if a=90 then text x3,y3,"E",CM


run this and you get the following



Which is almost right... but you can see that 0 degrees is not North and 90 degrees is not East.... There are two things happening here. Look at the original formula drawing (below)


First off, an angle of zero degrees (t in the above diagram) would actually point East along the x axis... so that's problem number one. This is easily fixed by subtracting 90 degrees from the angle we are using.

The next problem is that with this diagram, 90 degrees (East) would point straight up along the Y-axis. However graph paper has the origin point 0,0 in the bottom left (i.e. positive values of Y go up the page) and our CMM drawing page has 0,0 at the top left (with positive values of Y going down the page). By a happy coincidence though, what this means is that although the calculation goes counter/anti-clockwise, for our purposes we want to go clockwise... so we don't need to change anything on that score.

So the final program looks something like this

option angle degrees
for a=0 to 360 step 5
  ' NOTE: I have added the 200 offset to the calcs below to keep the later code cleaner
 x1=cos(a)*90 + 200
 y1=sin(a)*90 + 200
 x2=cos(a)*100 + 200
 y2=sin(a)*100 + 200
 x3=cos(a-90)*110 + 200
 y3=sin(a-90)*110 + 200
 line x1,y1,x2,y2
 if a=0 then text x3,y3,"N",CM
 if a=90 then text x3,y3,"E",CM
 if a=180 then text x3,y3,"S",CM
 if a=270 then text x3,y3,"W",CM
next a


Which should give you something like this (apologise for the dusty screen).  



Edited 2020-12-05 04:32 by PeteCotton
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:04pm 04 Dec 2020
Copy link to clipboard 
Print this post

That is absolutely brilliant Pete
option angle degrees won't work on my mmbasic unforuntately
I gave it a quick go, and it said
Option angle degrees
Invalid option
I'm still reading it trying to digest it  
Just read up on radians and degrees - they are all new to me
but apparently 1Deg × pi/180 = 0.01745Rad
so I should be able to do something like Radian = Deg*0.01745

Edit: found the bit where you said the same :)
I'll get there eventually  
Edited 2020-12-05 06:13 by lew247
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 08:36pm 04 Dec 2020
Copy link to clipboard 
Print this post

I've kinda got success
but I've gone wrong somehow



a = a*0.01745
for a=0 to 360 step 5
 ' NOTE: I have added the 200 offset to the calcs below to keep the later code cleaner
x1=cos(a)*90 + 200
y1=sin(a)*90 + 200
x2=cos(a)*100 + 200
y2=sin(a)*100 + 200
x3=cos(a-90)*110 + 200
y3=sin(a-90)*110 + 200
line x1,y1,x2,y2
if a=0 then text x3,y3,"N",CM
if a=90 then text x3,y3,"E",CM
if a=180 then text x3,y3,"S",CM
if a=270 then text x3,y3,"W",CM
LINE mm.hres/2,mmvres/2,LT,2, 2, RGB(WHITE)
next a
print finished 'so I can see the program has stopped


EDIT:

I tried it with for a=0*PI/180 to 360 step 5 and i's still the same result
Edited 2020-12-05 06:56 by lew247
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 09:06pm 04 Dec 2020
Copy link to clipboard 
Print this post

You can use the RAD(degrees) function to convert degrees to radians. So in your case it would be


ra = RAD(a)
x1=cos(ra)*90 + 200
y1=sin(ra)*90 + 200
.... and so forth
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 09:19pm 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  I've kinda got success
but I've gone wrong somehow

a = a*0.01745
for a=0 to 360 step 5
 ' NOTE: I have added the 200 offset to the calcs below to keep the later code cleaner
x1=cos(a)*90 + 200
y1=sin(a)*90 + 200
.....
next a
print finished 'so I can see the program has stopped




You almost had it. The a=a*0.01745 needs to be inside the loop and you would need to use another variable instead of "a" to hold the result, as "a" is the variable used by the for-next loop.

So normally, in the first pass through the loop, "a" would be equal to 0, second pass "a" would be equal to 5, third pass "a" would be equal to 10.

If you put a = a*0.01745 inside the loop, you are modifying the value of the variable "a", which the for-next loop is using to count how many times it loops, which will confuse the for-next loop code.

So in the first pass "a" will be equal to 0 as before, you will multiple it by 0.01745 which will still be zero. The second time "a" will start out as 5, you will change "a" to 5*0.01745=0.08725. The third time through the loop, "a" is starting at 0.08725 (instead of 5), so it will add the step value to "a" (+5) making it 5.08752 which you then multiply by 0.01745 which brings "a" back to 0.08877... so in essence, the variable "a" will take tens of thousands of loops to make it up to 360 (the end of the loop). (As opposed to only 72 steps of +5 before).

You should avoid altering the looping variable (until you are far more comfortable with it at least). So if you use another variable, as I did in my previous post for RADS, then it should work.


for a=0 to 360 step 5
 ra = a*0.01745
 ' NOTE: I have added the 200 offset to the calcs below to keep the later code cleaner
 x1=cos(ra)*90 + 200
 y1=sin(ra)*90 + 200
.....
next a

Edited 2020-12-05 07:23 by PeteCotton
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:25pm 04 Dec 2020
Copy link to clipboard 
Print this post

Brilliant
I now have a perfect compass
but
for some reason the direction letters are out
This is with a for the text lines

This is with ra for the text lines

Edited 2020-12-05 07:26 by lew247
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 09:34pm 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  Brilliant
I now have a perfect compass
but
for some reason the direction letters are out

Can you post your code please?
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:41pm 04 Dec 2020
Copy link to clipboard 
Print this post

CLS
for a =0  to 360 step 5
ra = RAD(a)
x1=cos(ra)*90 + 200
y1=sin(ra)*90 + 200
x2=cos(ra)*100 + 200
y2=sin(ra)*100 + 200
x3=cos(ra-90)*110 + 200
y3=sin(ra-90)*110 + 200
line x1,y1,x2,y2
if a=0 then text x3,y3,"N",CM
if ra=0 then text x3,y3,"N",CM 'didn't work
if a=90 then text x3,y3,"E",CM
if ra=90 then text x3,y3,"E",CM 'didn't work
if a=180 then text x3,y3,"S",CM
if ra=180 then text x3,y3,"S",CM 'didn't work
if a=270 then text x3,y3,"W",CM
if ra=270 then text x3,y3,"W",CM 'didn't work
next a
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:48pm 04 Dec 2020
Copy link to clipboard 
Print this post

I do have another question
How do you position the centre/pivot point of the radius?  ie to draw the circle around the centre of the screen?
I thought it would be
x = mm.hres/2
y = mm.vres/2
Edited 2020-12-05 07:50 by lew247
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 09:48pm 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  
CLS
for a =0  to 360 step 5
ra = RAD(a)
x1=cos(ra)*90 + 200
y1=sin(ra)*90 + 200
x2=cos(ra)*100 + 200
y2=sin(ra)*100 + 200
x3=cos(ra-90)*110 + 200
y3=sin(ra-90)*110 + 200
line x1,y1,x2,y2
if a=0 then text x3,y3,"N",CM
if ra=0 then text x3,y3,"N",CM 'didn't work
if a=90 then text x3,y3,"E",CM
if ra=90 then text x3,y3,"E",CM 'didn't work
if a=180 then text x3,y3,"S",CM
if ra=180 then text x3,y3,"S",CM 'didn't work
if a=270 then text x3,y3,"W",CM
if ra=270 then text x3,y3,"W",CM 'didn't work
next a


Ah yes. ra is the value in radians. So it will be somewhere between 0 and 6.283 (2*Pi). a is the value in degrees, so it will be somewhere between 0 and 360. I think you are getting confused between the radian and degree values.

That's why your "if ra=90 then" lines don't work. Because ra is always much smaller than 90, and therefore will never reach 90.

It is also why the text is off. The value "ra" in these two lines are now in radians (they were in degrees before - so subtacting 90 degrees was valid).

x3=cos(ra-90)*110 + 200
y3=sin(ra-90)*110 + 200

So subtracting 90 from them is going to give some unexpected result. 90 degrees in Radians is (0.5*Pi = 1.5707).

So the lines should read

x3=cos(ra-1.5707)*110 + 200
y3=sin(ra-1.5707)*110 + 200
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 09:51pm 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  I do have another question
How do you position the centre of the radius?  ie to draw the circle around the centre of the screen?
I thought it would be
x = mm.hres/2
y = mm.vres/2


Almost there. In my previous example I added 200 to the x and the y to make them appear away from the origin. Instead off 200, you need to add mm.hres/2 to the x values and mm.vres/2 to the y values.

CLS
for a =0  to 360 step 5
ra = RAD(a)
x1=cos(ra)*90 + mm.hres/2
y1=sin(ra)*90 + mm.vres/2
x2=cos(ra)*100 + mm.hres/2
y2=sin(ra)*100 + mm.vres/2
x3=cos(ra-1.5707)*110 + mm.hres/2
y3=sin(ra-1.5707)*110 + mm.vres/2
....
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 09:56pm 04 Dec 2020
Copy link to clipboard 
Print this post

Thank you so much :)


Edited 2020-12-05 07:57 by lew247
 
PeteCotton

Guru

Joined: 13/08/2020
Location: Canada
Posts: 527
Posted: 10:19pm 04 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  Thank you so much :)


You are very welcome!  
 
yock1960
Senior Member

Joined: 18/08/2020
Location: United States
Posts: 167
Posted: 01:06am 05 Dec 2020
Copy link to clipboard 
Print this post

Here is what I have so far. I still have a few things I'm scratching my head about, namely the positioning for the rotated text, as is, the rotated images don't scale correctly if the wid% parameter is changed. Graphics primitive angles in radians had me confused for a while! I'll give this a bit more work....a fun exercise!

Steve





option explicit

mode 1,8
CLS

dim cx% = 230
dim cy% = 260
dim wid% = 100
dim ang! = 0.087266463


compass_rose cx%, cy%, wid%

compass_rose 530,400,100


do while inkey$ = ""
loop


sub compass_rose cx%,cy%,wid%
 local a%


 for a% = 0 to 90
 line (cx%+15)+(cos(a%*ang!)*(wid%*.85)),(cy%+15)-(sin(a%*ang!)*(wid%*.85)),(cx%+15)+(cos(a%*ang!)*(wid%*.9)),(cy%+15)-(sin(a%*ang!)*(wid%*.9)),,RGB(WHITE)
 next


 
 text cx%+9,cy%-wid%+5,"N",L,2,,RGB(WHITE),RGB(BLACK)
 text cx%+9,cy%+wid%+5,"S",L,2,,RGB(WHITE),RGB(BLACK)

 text cx%+wid%+8,cy%+4,"E",L,2,,RGB(WHITE),RGB(BLACK)
 text cx%-wid%+8,cy%+4,"W",L,2,,RGB(WHITE),RGB(BLACK)



 text 10,10,"NE",L,7,,RGB(WHITE),RGB(BLACK)
 image rotate 6,4,30,30,cx%+wid%/2,cy%-wid%/2,45
 text 10,10,"SE",L,7,,RGB(WHITE),RGB(BLACK)
 image rotate 6,4,30,30,cx%+wid%/2,cy%+wid%/2,135
 text 10,10,"SW",L,7,,RGB(WHITE),RGB(BLACK)
 image rotate 6,4,30,30,cx%-wid%/2,cy%+wid%/2,225
 text 10,10,"NW",L,7,,RGB(WHITE),RGB(BLACK)
 image rotate 6,4,29,29,cx%-wid%/2,cy%-wid%/2,315

 circle cx%+15,cy%+15,wid%-16
 circle cx%+15,cy%+15,wid%-13



 triangle cx%+15,cy%-wid%+25,cx%+15+7,cy%+15,cx%+15-7,cy%+15,RGB(WHITE),RGB(WHITE)
 triangle cx%+15,cy%+wid%+8,cx%+15+7,cy%+15,cx%+15-7,cy%+15,RGB(WHITE),RGB(WHITE)
 triangle cx%+15-wid%+3,cy%+15,cx%+15,cy%+15+7,cx%+15,cy%+15-7,RGB(WHITE),RGB(WHITE)
 triangle cx%+15+wid%-3,cy%+15,cx%+15,cy%+15+7,cx%+15,cy%+15-7,RGB(WHITE),RGB(WHITE)


for a% = 1 to 8
 triangle cx%+15-sin(9*a%*ang!)*wid%*.4,cy%+15-cos(9*a%*ang!)*wid%*.4,cx%+15+cos(9*a%*ang!)*5,cy%+15-sin(9*a%*ang!)*5,cx%+15-cos(9*a%*ang!)*5,cy%+15+sin(9*a%*ang!)*5,RGB(WHITE),RGB(WHITE)
next


end sub
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025