Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 26th October 2011, 10:53   #1  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
arccos function

Hi,
I need an accurate arccos function in avisynth script. I tried the one from.. can't remember it's name, but it's not accurate enough and is limiting my application.
I'm not setup for plugin development either; I hate to get sidetracked for an hour just to write a plugin for one function - argh. If anyone is setup for development, would you consider writing a arcsin, arccos, and atan2 functions? It should be 5 minutes for you I really need it to finish researchiing my software TBC.

Anyhow, here's the inaccurate function:
Code:
	Function __arc_sin(float x, float "__prev", int "__step", float "__pterm")
	{
		__prev  = Default(__prev, x)
		__pterm = Default(__pterm, x)
		__step  = Default(__step, 1) # step 0 is introduced by defaults
		st2 = 2 * __step
		t = st2 - 1
		term = __pterm * (Float(t * t) / Float(st2 * (st2 + 1))) * (x * x)
		return Abs(term) > 0.00001 \
			? __arc_sin(x, __prev + term, __step + 1, term) \
			: __prev + term
	}

Function ArcSin(float x) { return __arc_sin(x) }

Function ArcCos(float x) { return (Pi/2) - ArcSin(x) }
Thanks.
jmac698 is offline   Reply With Quote
Old 26th October 2011, 12:07   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,383
Here you go.

Includes the functions:
Acos(float)
Asin(float)
Atan(float)
Atan2(float, float)

They are simply wrappers for the corresponding C functions, so see the relevant C documentation for details.
Attached Files
File Type: zip ArcFuns.zip (28.6 KB, 136 views)
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 26th October 2011 at 12:26. Reason: correct description of Atan2
Gavino is offline   Reply With Quote
Old 26th October 2011, 14:12   #3  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867

That template will be really useful. With the recent minmax plugin I should be able to quickly write a few things, when I can get vcexpress setup.
Wait until you see my upcoming "perfect TBC" it's quite amazing, subpixel accuracy to 1/5 pixel but with new arccos function, even 1/100 pixel
jmac698 is offline   Reply With Quote
Old 26th October 2011, 14:16   #4  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
For avisynth news:
New plugin ArcFuns
Name: ArcFuns
Version: 1.0
Author: Gavino
Description: This plugin expands the available numerical functions with missing inverse trig functions.
Usage:
acos(float arg)
asin(float arg)
atan(float arg)
atan2(float y, float x)
Each perfoms the calculation as in the C language and returns a float value.
Atan2 is the angle of the point (x,y) from the line y=0, and is positive for anticlockwise. It can be quite useful for calculating hue, for example, from U, V.

Last edited by jmac698; 27th October 2011 at 10:22. Reason: Updated
jmac698 is offline   Reply With Quote
Old 26th October 2011, 23:22   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,383
Quote:
Originally Posted by jmac698 View Post
atan2(float x, float y)
Should be atan2(float y, float x) to be consistent with the rest of the description:
Quote:
Atan2 is the angle of the point (x,y) from the line x=0, and is positive for anticlockwise.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 27th October 2011, 00:05   #6  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
To be consistent with C, yes. I don't see how the description implies any order to the arguments in the function in itself; it's really the C function that determined it. Anyhow I don't see any sense of making it y,x in the first place.
jmac698 is offline   Reply With Quote
Old 27th October 2011, 00:31   #7  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 610
Same order as the quotient tan = sin / cos?
__________________
dither 1.27.2 for AviSynth | avstp 1.0.3 for AviSynth development | fmtconv r19 for Vapoursynth | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 27th October 2011, 01:47   #8  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
It's in y, x order in math books, who knows why they have this convention? Something historical or maybe they have a pattern to it.
jmac698 is offline   Reply With Quote
Old 27th October 2011, 10:03   #9  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,383
Actually, it's still not right - I've just spotted something else....
Quote:
Originally Posted by jmac698 View Post
[After editing]
atan2(float y, float x)
Atan2 is the angle of the point (x,y) from the line x=0, and is positive for anticlockwise.
It should be from the line y=0, ie the x-axis.

An alternative description which works is:
atan2(float x, float y)
Atan2 is the angle of the point (x,y) from the line x=0 (the y-axis), and is positive for clockwise.
But this is less conventional.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 27th October 2011, 10:22   #10  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
You have a great eye for detail! Maybe that's why you're such a good programmer
jmac698 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.