|
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace WpfCylinder
{
class WpfUtils
{
static double one_rad_in_degrees = (double)57.0 + ((double)17.0 / (double)60.0) + ((double)44.6 / ((double)3600.0));
public static Point3D RotatePointXY(Point3D p, Point3D rotation_point, double radians)
{
Point3D new_point = new Point3D(rotation_point.X, rotation_point.Y, rotation_point.Z);
try
{
if (radians != 0)
{
double ydiff = p.Y - rotation_point.Y;
double xdiff = p.X - rotation_point.X;
double xd = (xdiff * Math.Cos(radians)) - (ydiff * Math.Sin(radians));
double yd = (xdiff * Math.Sin(radians)) + (ydiff * Math.Cos(radians));
new_point.X += xd;
new_point.Y += yd;
new_point.Z = p.Z;
}
else
{
new_point.X = p.X;
new_point.Y = p.Y;
new_point.Z = p.Z;
}
}
catch
{
}
return new_point;
}
public static Point3D RotatePointXZ(Point3D p, Point3D rotation_point, double radians)
{
Point3D new_point = new Point3D(rotation_point.X, rotation_point.Y, rotation_point.Z);
try
{
if (radians != 0)
{
double ydiff = p.Z - rotation_point.Z;
double xdiff = p.X - rotation_point.X;
double xd = (xdiff * Math.Cos(radians)) - (ydiff * Math.Sin(radians));
double yd = (xdiff * Math.Sin(radians)) + (ydiff * Math.Cos(radians));
new_point.X += xd;
new_point.Z += yd;
new_point.Y = p.Y;
}
else
{
new_point.X = p.X;
new_point.Y = p.Y;
new_point.Z = p.Z;
}
}
catch
{
}
return new_point;
}
public static Point3D RotatePointZY(Point3D p, Point3D rotation_point, double radians)
{
Point3D new_point = new Point3D(rotation_point.X, rotation_point.Y, rotation_point.Z);
try
{
if (radians != 0)
{
double ydiff = p.Y - rotation_point.Y;
double xdiff = p.Z - rotation_point.Z;
double xd = (xdiff * Math.Cos(radians)) - (ydiff * Math.Sin(radians));
double yd = (xdiff * Math.Sin(radians)) + (ydiff * Math.Cos(radians));
new_point.Z += xd;
new_point.Y += yd;
new_point.X = p.X;
}
else
{
new_point.X = p.X;
new_point.Y = p.Y;
new_point.Z = p.Z;
}
}
catch
{
}
return new_point;
}
public static double radians_from_degrees(double degrees)
{
return degrees / one_rad_in_degrees;
}
public static double degrees_from_radians(double radians)
{
return radians * one_rad_in_degrees;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Gary Miller is a professional software developer whose clients have included Delta Air Lines, Cingular Wireless, and the Center For Disease Control. He has developed advanced graphical user interfaces for traffic control systems and medical call centers. Some animated 3D products he has developed include
Field Artist and
Calder4D. He has developed a Silverlight powered social networking site for music students called
Field Artist Central
Calder4D is a Windows program that allows you to model and animate 3D shapes and then produces the XAML code to include those animated shapes in your own WPF applications.