//*************************************************************** // Copyright 2008 Centre For Advanced Spatial Analysis, UCL // // Author: Joel Dearden, University College London // // Contact: j.dearden@ucl.ac.uk // // Joel Dearden, // Centre for Advanced Spatial Analysis, // University College London, // 1-19 Torrington Place, // London, // WC1E 7HB // // // This file is part of PedTrace. // // PedTrace is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // PedTrace is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with PedTrace. If not, see . // //*************************************************************** using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; /// /// Summary description for PTPoint /// /// namespace pedTrace { public class PTPoint { public float fX; public float fY; public float fZ; //use only to determine which floor a point should be on when drawing public PTPoint(float x, float y, float z) { fX = x; fY = y; fZ = z; } public static PTPoint multiplyVectorByScalar(PTPoint v, float s) { PTPoint m = new PTPoint(0, 0, 0); m.fX = v.fX * s; m.fY = v.fY * s; return m; } public static PTPoint normaliseVector(PTPoint v) { PTPoint n = new PTPoint(0, 0, 0); float length = PTPoint.vectorLength(v); n.fX = v.fX / length; n.fY = v.fY / length; return n; } public static float vectorLength(PTPoint v) { return (float) Math.Sqrt(Math.Pow(v.fX, 2) + Math.Pow(v.fY, 2)); } public static PTPoint directionVector2D(float orientation) { PTPoint zeroVector = new PTPoint(1, 0, 0); PTPoint rotatedVector = new PTPoint(0, 0, 0); rotatedVector.fX = (float)((zeroVector.fX * Math.Cos(orientation)) - (zeroVector.fY * Math.Sin(orientation))); rotatedVector.fY = (float)((zeroVector.fX * Math.Sin(orientation)) + (zeroVector.fY * Math.Cos(orientation))); return rotatedVector; } public static PTPoint XAxisFromYAxis(PTPoint yVector) { PTPoint xVector = new PTPoint(yVector.fY, (0.0F - yVector.fX), 0); return xVector; } public static PTPoint addVector(PTPoint v1, PTPoint v2) { PTPoint added = new PTPoint( v1.fX + v2.fX, v1.fY + v2.fY, v1.fZ + v2.fZ ); return added; } public static PTPoint subtractVector(PTPoint v1, PTPoint v2) { PTPoint sub = new PTPoint( v1.fX - v2.fX, v1.fY - v2.fY, v1.fZ - v2.fZ ); return sub; } } }