Way to find the points of where startAngle and circle meet

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Way to find the points of where startAngle and circle meet

Post by magice » Thu Jan 29, 2015 3:06 am

What I need is a way to retrieve the points values of where a circle circumference and a line from it's center at the startAngle would cross. I was hoping that it was a property, but it seems that I will need a formula. Trigonometry is not one of my strengths, so can someone make it simple?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Way to find the points of where startAngle and circle me

Post by dunbarx » Thu Jan 29, 2015 6:51 am

Hi.

Well, since you are going to have to work in a cartesian field of pixels, you will have to do a little math. Try this. Make a circle graphic, and name it "circle". make a line graphic and name it "line". Make one field. Place the circle somewhere on the card. Make a button with this in its script:

Code: Select all

on mouseUp
   put the height of grc "circle" / 2 into r
   put item 1 of the loc of grc "circle" into a
   put item 2 of the loc of grc "circle" into b
   
   put random(10) into arg
   --put "-" & random(10)  into arg --try this as well, but first comment out the line just above
   put r * sin(pi/arg) + a into x
   put r * cos(pi/arg) + b into y
   
   set the points of grc "line" to the loc of grc "circle" & return & x & "," & y
   put trunc(x) & "," & trunc(y) into fld 1
end mouseUp
Click on the button a few times. Now this is just a starter. You need to get to all four quadrants. But can you take this and create the effect you need? I am not sure if you want to make a line and see where the intersect is, or select a point and create the line. The above sort of does the latter. The intersect is in the field.

Write back, I suspect there is much to do...

Craig Newman

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Thu Jan 29, 2015 2:53 pm

Thank you Craig. I will be playing with this for the next several hours. I can see where the answer to my question lies somewhere in there. I just need to figure out how to tie "arg" and the surrounding formula to a 0-360 scale. It may take awhile, but I think I can figure it out. Heck, I'm just proud of myself for figuring out that the line

Code: Select all

 set the points of grc "line" to the loc of grc "circle" & return & x & "," & y
needed to be

Code: Select all

set the points of grc "line" to the loc of grc "circle" & return & trunc(x) & "," &trunc(y)
:twisted:
I'm sure I will be asking more on this subject, but you gave me a great start.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Way to find the points of where startAngle and circle me

Post by dunbarx » Thu Jan 29, 2015 3:36 pm

Hi.

LC either ignores fractional "point" values, or rounds them. But having such things does not throw an error. I included "trunc" in the last line just to make the result readable and ordinary for display.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Way to find the points of where startAngle and circle me

Post by dunbarx » Thu Jan 29, 2015 3:38 pm

Hermann.

We need you here.

Craig

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Thu Jan 29, 2015 5:54 pm

ok I think I am on to something. I made a slider with a start value of 1 and an end value of 360.
in it I put this code:

Code: Select all

on scrollbarDrag tNew
      put the height of grc "circle" / 2 into r
   put item 1 of the loc of grc "circle" into a
   put item 2 of the loc of grc "circle" into b   
   set the startAngle of graphic "circle" to (tNew-90)
    put r* sin(tNew/57.3) + a into x
   put r* cos(tNew/57.3)+ b into y
   
   set the points of grc "line" to (the loc of grc "circle" &cr & trunc(x) & "," & trunc(y))
   put trunc(x) & "," & trunc(y) into fld 1
   
end scrollbarDrag
I came up with this by trial and error. The question is why 57.3? this seems to be the magic number for all sized circles.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Thu Jan 29, 2015 6:05 pm

Nevermind i think I figured out the connection. 180/57.3 is darn close to pi so I should be able to refine this with a little work :D

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Thu Jan 29, 2015 7:03 pm

and the final results are:

Code: Select all

function startAnglePoints tA tB tH tSa
   --tA is the loc of the circle part 1
   --tB is the loc of the circle part 2
   --tH is the height of the circle
   --tS is the startAngle of the circle
   put( tH / 2) into r
   add 90 to tSa
   put r* sin(tSa/(180/pi)) + tA into x
   put r* cos(tSa/(180/pi))+ tB into y
   return (trunc(x)&cr&trunc(y))
end startAnglePoints
Thank you Craig. You are the man.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Way to find the points of where startAngle and circle me

Post by dunbarx » Thu Jan 29, 2015 7:33 pm

No problem.

Do you know what a "radian" is? Do you now see "why" a radian is?

Craig

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Thu Jan 29, 2015 7:54 pm

dunbarx wrote:No problem.

Do you know what a "radian" is? Do you now see "why" a radian is?

Craig
I am starting to now that you have pointed it out for me to look up. :D Please forgive my mathematical ineptitude. When I graduated high school over 30 years ago, the only math I was interested in was figuring out how many beers I could get out of a paycheck. Everything else has been self taught, and most of the time I feel like I need a new teacher.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Way to find the points of where startAngle and circle me

Post by Simon » Thu Jan 29, 2015 8:00 pm

magice,
When I got out of high school I cut the paycheck out of the equation and thought I should be paid in beer :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Fri Jan 30, 2015 3:08 am

Simon wrote:magice,
When I got out of high school I cut the paycheck out of the equation and thought I should be paid in beer :)

Simon
LOL, Thankfully I quit drinking, and in a moment of sober boredom I discovered that I love math. Now that paycheck is starting to finally be a bigger part of the equation. 8)

Oh and BTW, for anyone who might find it useful I decided that since the circle referenced in the function contains all of the data needed by the function, it would be much cleaner to have only the circle name as an argument.

Code: Select all

function startAnglePoint theCircle
   --theCircle is the name of the circle graphic
   put (the height of graphic theCircle /2 )into r
   put the startAngle of graphic theCircle +90 into tSa
   put the first item in the loc of graphic theCircle into tA
   put the second item in the loc of graphic theCircle into tB
   put r* sin(tSa/(180/pi)) + tA into x
   put r* cos(tSa/(180/pi))+ tB into y
   return (trunc(x)&cr&trunc(y))
end startAnglePoint

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Way to find the points of where startAngle and circle me

Post by magice » Sat Jan 31, 2015 2:40 am

I made a couple changes. As my project progressed it became obvious that I needed a way to offset the target points a specific number of degrees away from the startAngle, so I added an argument for doing that. I also discovered that the cr in the return value only worked with part of what I needed so I changed it to a comma.

Code: Select all

function startAnglePoint theCircle tV
   --theCircle is the name of the circle graphic
   --tV is a number of degrees of variation
   put (the height of graphic theCircle /2 )into r
   put the startAngle of graphic theCircle +90+tV into tSa
   put the first item in the loc of graphic theCircle into tA
   put the second item in the loc of graphic theCircle into tB
   put r* sin(tSa/(180/pi)) + tA into x
   put r* cos(tSa/(180/pi))+ tB into y
   return (trunc(x)&comma&trunc(y))
end startAnglePoint
After finishing my project, I started playing with this function. By creating a point on a circles circumference that a line can attach to, and adjusting the start angle you can create a rotation. This turns the circle into a motor that can run all kinds of mechanical simulations and effects with very little code. This stack is the result of boredom and discovering what this can do. Change the visibility of objects to see how it is connected.
Attachments
startAnglePoints.rar
(2.15 KiB) Downloaded 166 times

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”