From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 11 18:00:35 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 488DF16A401; Sun, 11 Feb 2007 18:00:35 +0000 (UTC) (envelope-from stephen@math.missouri.edu) Received: from math.missouri.edu (math.missouri.edu [128.206.184.200]) by mx1.freebsd.org (Postfix) with ESMTP id 16F6313C428; Sun, 11 Feb 2007 18:00:34 +0000 (UTC) (envelope-from stephen@math.missouri.edu) Received: from math.missouri.edu (stephen@localhost [127.0.0.1]) by math.missouri.edu (8.13.1/8.13.1) with ESMTP id l1BI0D2N099169; Sun, 11 Feb 2007 12:00:13 -0600 (CST) (envelope-from stephen@math.missouri.edu) Received: from localhost (stephen@localhost) by math.missouri.edu (8.13.1/8.13.1/Submit) with ESMTP id l1BI0CSN099164; Sun, 11 Feb 2007 12:00:12 -0600 (CST) (envelope-from stephen@math.missouri.edu) Date: Sun, 11 Feb 2007 12:00:12 -0600 (CST) From: Stephen Montgomery-Smith To: Daniel Eischen In-Reply-To: <20070211110815.O62469@math.missouri.edu> Message-ID: <20070211115815.O62469@math.missouri.edu> References: <45CED641.7020608@ab.ote.we.lv> <20070211110815.O62469@math.missouri.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: ClamAV 0.88/2552/Sun Feb 11 03:56:14 2007 on math.missouri.edu X-Virus-Status: Clean Cc: "Eugene M. Kim" , hackers@freebsd.org Subject: Re: sin()/cos()/tan() for kernel code? '_ 'a X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Feb 2007 18:00:35 -0000 On Sun, 11 Feb 2007, Stephen Montgomery-Smith wrote: > > > On Sun, 11 Feb 2007, Daniel Eischen wrote: > >> On Sun, 11 Feb 2007, Eugene M. Kim wrote: >> >>> Hello all, >>> >>> I am writing a mouse device driver for my Wacom tablet (Intuos 2 9x12). >>> The tablet comes with a mouse and I managed to get valid coordinate data >>> from the device. However, unlike usual mice, the coordinate system is >>> tied not to the orientation of the mouse itself, but to the tablet, >>> which acts much like a "mouse pad". So, for example, if I rotate the >>> mouse 30 degrees to the left and move it left and right, the mouse >>> cursor would move not horizontally, but to 2- or 8-o'clock. >>> >>> Fortunately the mouse also provides orientation data along with >>> coordinate data, so the correct cursor movement could be calculated from >>> it. The problem: The calculation needs trigonometry, but there seems to >>> be no math library support in the kernel (I ran "grep -w cos" on the >>> -CURRENT source tree, which turned nothing up). >>> >>> Does anyone have an idea on how to do this? >> >> Can't you do this in userland? Teach moused? > > Since you will only need sin and cos evaluated to the nearest degree, if > that, I suggest a simple look up table. There is also something called the > CORDIC method, I think, but I suspect that the look up table will be so much > easier to program, and negligable extra space overhead. > > Stephen And if you do need more accuracy than the nearest degree, the formulae sin(x+h) = sin(x) + h cos(x); cos(x+h) = cos(x) - h sin(x) for small h (say |h| less than half a degree) should provide way more accuracy than you should need.