Trigo help please.

Hello,

The distance between two points is trivial and can be done in ASOC. But what about the angle?

Given two points (x1,y1) and (x2,y2) how do I get tan(Exp-1)(y2-y1/x2-x1) ?

Thanks!

After edit: ok, there is no way to do it nor in Applescript, neither in ASOC. QuickDraw had a nice function called PtToAngle (aPoint, aRect, returnedAngle) which gave an angle (in deg) between a rectangle and a point. Such a function survived a time in CarbonLib (::ptToAngle) but the freshest source on the web is outdated (2004).

So I’m looking for a replacement (atan): is it part of the C/C++ languages or is there a library somewhere which provides the equivalent (even in rad)?

My question is probably too trivial, as I found nothing in the docs. Is it a kind of “As everybody knows.”?

It’s part of the standard C libraries, so you’ll have to make an Objective-C class to use it. This should do:

@implementation Trig
-(double)findAtan:(double)num { return atan(num); }
@end

Then just call it:

		set trigger to current application's Trig's alloc()'s init()
		log trigger's findAtan_(34)

Working. In radians, I presume.

So it’s that simple to make a Objective-C class and create an instance of it? And once the message is sent, the housekeeping is done for me? Well, my perspectives are enlarged : ASOC is also a gate to raw C and C++.

Thank you Shane :smiley:

Yep, pretty much.

Remember that Objective-C is just C with some other stuff tacked on. (I gather things are a bit more complicated with C++, but I’ve never touched it.)