Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

arcticBear

find a tangent line to a circle based on a point on the circle??

This topic is 5731 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a screen with a ring on it (generally its just a circle), and u can click on any point on the ring (edge of circle).. what i want it to do is draw a tangent line on that point.. for instance, if i clicked the very top middle point on the circle, it would draw like this:
_
O
 
and if i clicked like the "corners" of the circle (45 degrees, 135, etc) it would draw a 45 degree line on that point.. what equation could do this for me? do i have to take the derivative or something? thanks

Share this post


Link to post
Share on other sites
Advertisement
Yup, mathmatically anyways, derivitives are the way to go. Your circle is defined by (x-h)^2+(y-k)^2=r^2, where r is your radius, and the point(h,k) is the centre of your circle. Then you take the derivative of your function, and find the value of your derivative at the point clicked. This is the slope of your line, so you will have y = (slope)*x+c. Then if you plug in the point clicked on, you will get the equation to the tangent. There may be better ways to do this, but that''s how you would do it in calculus.

Share this post


Link to post
Share on other sites
here is a small way of calculating the gradient of the circle... so you could calculate the tangent from it...

| x <- x (in) position where (0,0) is the centre
| y <- y (in) position
| Angle <- (out) final angle in degrees that is calculated
| Atn() <- Inverse Tan function

Angle = Atn(-Ay / Ax) / 3.1415 * 180
If Ax > 0 Then Angle = Angle + 90
If Ax < 0 Then Angle = Angle + 270

there that should do it..... also note that a division by zero can occur here... so here is the how I work around it

if Ax <> 0 then Angle = Atn(-Ay / Ax) / 3.1415 * 180
If Ax > 0 Then Angle = Angle + 90
If Ax < 0 Then Angle = Angle + 270
If Ax = 0 And Ay > 0 Then Angle = 0
If Ax = 0 And Ay < 0 Then Angle = 180

(note. since "-Ay/Ax" is the gradient of the circle... the tangent is "Ax/Ay")

Hope that helps.....

Share this post


Link to post
Share on other sites
Hi again...

when I think about it... you don''t need any of that....
just draw a tangent to the appropriate position to the gradient "x/y" where x and y is the coordinate of the circle where the tangent is to be draw where centre of the cicle is (0,0).....

Share this post


Link to post
Share on other sites
If you want a line perpendicular to the vector (x,y), then (-y,x) and (y,-x) are two such vectors. So if the circle was centered at the origin and the user clicked (x,y) on the circle then a line from (x,y)+(-y,x)=(x-y,x+y) to (x,y)+(y,-x)=(x+y,-x+y) would be tangent to it.

Share this post


Link to post
Share on other sites
quote:
Original post by Modena_au
OMG!!! That is 10 million times easier than what I was thinking, lol.


Ha Ha! But, of course, that easy approach only works for circles and spheres! Some variation of your approach is still appropriate for general shapes!



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!