We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › tangent angle between 2 points
Page Index Toggle Pages: 1
tangent angle between 2 points (Read 1202 times)
tangent angle between 2 points
Jul 7th, 2008, 10:27pm
 
Hi,
I'm trying to create a function that creates a curved triangle strip from a list of vertices - so I need to know how to get the 90 degree tangent angle between 2 points.  I'm within beginshape() so cant use translate/rotate.

so for example i have point A (x,y) and point B (x,y), and need a third point at a rightangle tangent, to create the triangle aligning to the curve.

I was looking at vector3d libraries - there is a .cross method which calculates this for me i think- is this the right way to go? i'm still unsure,

thanks,
Glenn.
Re: tangent angle between 2 points
Reply #1 - Jul 7th, 2008, 10:51pm
 
i think you'll figure something out with atan2 :
http://processing.org/reference/atan2_.html
Re: tangent angle between 2 points
Reply #2 - Jul 7th, 2008, 11:18pm
 
I've used atan before to get what I want, but because I'm inside a beginshape() function, i cant use translate/rotate to make use of atan.  my vertex list also part of a particle class which isnt affected by translate/rotate either.

so it will have to be lots of math or maybe that .cross vector method.



Re: tangent angle between 2 points
Reply #3 - Jul 8th, 2008, 12:02am
 
Code:
float x1,y1,x2,y2; 
float width;
//set these to the values of the two points...
float ang=atan2(y2-y1,x2-x1)+HALF_PI; //might be -HALF_PI
float x3=width*cos(ang); //might be sin..
float y3=width*sin(ang); //might be cos if above is sin
Re: tangent angle between 2 points
Reply #4 - Jul 8th, 2008, 10:28am
 
Thanks John, I'll try this out today.

G.
Re: tangent angle between 2 points
Reply #5 - Jul 8th, 2008, 4:32pm
 
Brilliant John Thanks,

I then added x3,y3 to x1,y1 to get the final coordinate for the triangle.  Working okay now.

Cheers,
G.
Page Index Toggle Pages: 1