Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to plot a tangent to a circle from the middle

Subject: How to plot a tangent to a circle from the middle

From: Kenneth Galea

Date: 6 Apr, 2010 11:41:03

Message: 1 of 5

Hi everyone.

I'm trying to plot a tangent (red line) to a circle but I'm having a little problem on how to draw it from the middle. This is what I'm obtaining:
http://dl.dropbox.com/u/5800838/untitled.jpg

The angle is fine but the tangent is not drawn at its middle. This is a section of my code:
 x1 =Major_axis_intersections(1,2) %start point of line P1
    y1 =Major_axis_intersections(1,1)
    x2 =Major_axis_intersections(2,2) %end point of line P2
    y2 =Major_axis_intersections(2,1)

d = 32 %distance/length of vector plotted
    %Computing a tangent (to the circle) to the Grasping line
     t = sqrt((x2-x1)^2+(y2-y1)^2);
     x3 = x1-((y2-y1)*d/t);
     y3 = y1+((x2-x1)*d/t);
     line([x1 x3], [y1 y3] , 'Color','r', 'LineStyle','-', 'LineWidth', 3)

Regards
Kenneth

Subject: How to plot a tangent to a circle from the middle

From: Roger Stafford

Date: 6 Apr, 2010 14:23:04

Message: 2 of 5

"Kenneth Galea" <k.galea@hotmail.com> wrote in message <hpf6kf$t0k$1@fred.mathworks.com>...
> Hi everyone.
>
> I'm trying to plot a tangent (red line) to a circle but I'm having a little problem on how to draw it from the middle. This is what I'm obtaining:
> http://dl.dropbox.com/u/5800838/untitled.jpg
>
> The angle is fine but the tangent is not drawn at its middle. This is a section of my code:
> x1 =Major_axis_intersections(1,2) %start point of line P1
> y1 =Major_axis_intersections(1,1)
> x2 =Major_axis_intersections(2,2) %end point of line P2
> y2 =Major_axis_intersections(2,1)
>
> d = 32 %distance/length of vector plotted
> %Computing a tangent (to the circle) to the Grasping line
> t = sqrt((x2-x1)^2+(y2-y1)^2);
> x3 = x1-((y2-y1)*d/t);
> y3 = y1+((x2-x1)*d/t);
> line([x1 x3], [y1 y3] , 'Color','r', 'LineStyle','-', 'LineWidth', 3)
>
> Regards
> Kenneth

  You're making the same mistake as in your thread "Plot a line perpendicuar to another line from its midpoint" three days ago! You're using (x1,y1) as a base point. The 'line' arguments refer to its endpoints and you don't want (x1,y1) as an endpoint do you?

  You should be saying something like this:

 x3 = x1-((y2-y1)*d/2/t);
 y3 = y1+((x2-x1)*d/2/t);
 x4 = x1+((y2-y1)*d/2/t); % Endpoint in the opposite direction
 y4 = y1-((x2-x1)*d/2/t);
 line([x3 x4], [y3 y4] , 'Color','r', 'LineStyle','-', 'LineWidth', 3)

Roger Stafford

Subject: How to plot a tangent to a circle from the middle

From: Kenneth Galea

Date: 6 Apr, 2010 18:01:20

Message: 3 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hpfg48$r7k$1@fred.mathworks.com>...
> "Kenneth Galea" <k.galea@hotmail.com> wrote in message <hpf6kf$t0k$1@fred.mathworks.com>...
> > Hi everyone.
> >
> > I'm trying to plot a tangent (red line) to a circle but I'm having a little problem on how to draw it from the middle. This is what I'm obtaining:
> > http://dl.dropbox.com/u/5800838/untitled.jpg
> >
> > The angle is fine but the tangent is not drawn at its middle. This is a section of my code:
> > x1 =Major_axis_intersections(1,2) %start point of line P1
> > y1 =Major_axis_intersections(1,1)
> > x2 =Major_axis_intersections(2,2) %end point of line P2
> > y2 =Major_axis_intersections(2,1)
> >
> > d = 32 %distance/length of vector plotted
> > %Computing a tangent (to the circle) to the Grasping line
> > t = sqrt((x2-x1)^2+(y2-y1)^2);
> > x3 = x1-((y2-y1)*d/t);
> > y3 = y1+((x2-x1)*d/t);
> > line([x1 x3], [y1 y3] , 'Color','r', 'LineStyle','-', 'LineWidth', 3)
> >
> > Regards
> > Kenneth
>
> You're making the same mistake as in your thread "Plot a line perpendicuar to another line from its midpoint" three days ago! You're using (x1,y1) as a base point. The 'line' arguments refer to its endpoints and you don't want (x1,y1) as an endpoint do you?
>
> You should be saying something like this:
>
> x3 = x1-((y2-y1)*d/2/t);
> y3 = y1+((x2-x1)*d/2/t);
> x4 = x1+((y2-y1)*d/2/t); % Endpoint in the opposite direction
> y4 = y1-((x2-x1)*d/2/t);
> line([x3 x4], [y3 y4] , 'Color','r', 'LineStyle','-', 'LineWidth', 3)
>
> Roger Stafford

Yes , you're right. Please if possible do you have a link for an explanation or what method is used to obtain these equations...since its a been long time that I did such coordinate geometry...and I cannot find a reasonable explanation of these general equations!!??
Regards
Kenneth Galea

Subject: How to plot a tangent to a circle from the middle

From: Roger Stafford

Date: 6 Apr, 2010 19:11:04

Message: 4 of 5

"Kenneth Galea" <k.galea@hotmail.com> wrote in message <hpfstg$s3m$1@fred.mathworks.com>...
> Yes , you're right. Please if possible do you have a link for an explanation or what method is used to obtain these equations...since its a been long time that I did such coordinate geometry...and I cannot find a reasonable explanation of these general equations!!??
> Regards
> Kenneth Galea
------------------
  I would prefer to explain this myself rather than have to look up links. It is a very simple concept. I hope the following makes sense.

  The quantity [x2-x1,y2-y1] is a vector in the x-y plane starting at the point P1 = [x1,y1] and ending at P2 = [x2,y2]. If these components are divided by the distance between P1 and P2, which is your t, you get the unit vector

 [(x2-x1)/t,(y2-y1)/t]

which points along parallel to that first vector.

  Now if you rotate this unit vector 90 degrees counterclockwise, you get the unit vector [-(y2-y1)/t,(x2-x1)/t] (a basic theorem in analytic geometry.) If you add P1 plus d/2 times this last unit vector, you get

 P3 = [x3,y3] = [x1-(y2-y1)/t*d/2,y1+(x2-x1)/t*d/2]

which will be P3 off at a right angle to the left of P1 and a distance d/2 away. Now add to P1 the negative of that unit vector times d/2 to get the point P4 = [x4,y4] off to the right of P1 on the opposite side from P3 and a distance of d/2 away from P1:

 P4 = [x4,y4] = [x1+(y2-y1)/t*d/2,y1-(x2-x1)/t*d/2]

It follows that P3 and P4 will be a total distance of d apart from each other and have P1 at their midpoint, as was your request.

  These points P3 and P4 are then the endpoints for a line connecting them, so call 'line' accordingly, using P3 and P4 as arguments, and *please* don't use P1 as one of its endpoints!

Roger Stafford

Subject: How to plot a tangent to a circle from the middle

From: Kenneth Galea

Date: 7 Apr, 2010 09:27:05

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hpg108$3jp$1@fred.mathworks.com>...
> "Kenneth Galea" <k.galea@hotmail.com> wrote in message <hpfstg$s3m$1@fred.mathworks.com>...
> > Yes , you're right. Please if possible do you have a link for an explanation or what method is used to obtain these equations...since its a been long time that I did such coordinate geometry...and I cannot find a reasonable explanation of these general equations!!??
> > Regards
> > Kenneth Galea
> ------------------
> I would prefer to explain this myself rather than have to look up links. It is a very simple concept. I hope the following makes sense.
>
> The quantity [x2-x1,y2-y1] is a vector in the x-y plane starting at the point P1 = [x1,y1] and ending at P2 = [x2,y2]. If these components are divided by the distance between P1 and P2, which is your t, you get the unit vector
>
> [(x2-x1)/t,(y2-y1)/t]
>
> which points along parallel to that first vector.
>
> Now if you rotate this unit vector 90 degrees counterclockwise, you get the unit vector [-(y2-y1)/t,(x2-x1)/t] (a basic theorem in analytic geometry.) If you add P1 plus d/2 times this last unit vector, you get
>
> P3 = [x3,y3] = [x1-(y2-y1)/t*d/2,y1+(x2-x1)/t*d/2]
>
> which will be P3 off at a right angle to the left of P1 and a distance d/2 away. Now add to P1 the negative of that unit vector times d/2 to get the point P4 = [x4,y4] off to the right of P1 on the opposite side from P3 and a distance of d/2 away from P1:
>
> P4 = [x4,y4] = [x1+(y2-y1)/t*d/2,y1-(x2-x1)/t*d/2]
>
> It follows that P3 and P4 will be a total distance of d apart from each other and have P1 at their midpoint, as was your request.
>
> These points P3 and P4 are then the endpoints for a line connecting them, so call 'line' accordingly, using P3 and P4 as arguments, and *please* don't use P1 as one of its endpoints!
>
> Roger Stafford

Great explanation.

Regards
Kenneth

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us