[英]3d coordinates in plane c#
我正在尝试使用drawline方法显示3维轴,我设法使一条线绕其轴旋转,但是我无法使第二条线与该线成90度角旋转,我想实现基本的旋转方法,但是我不知道如何在c# http://en.wikipedia.org/wiki/Rotation_matrix中实现它。 我想知道如何将z轴放置在xy图表上。 请记住,我想在纯C#中执行此操作,而无需直接x或其他任何操作。
这是我绘图的基本代码
private void Go_Click(object sender, EventArgs e)
{
int radiusx1= Int32.Parse(xbarvalue.Text);
int radiusy1 = Int32.Parse(ybarvalue.Text);
int radiusz1 = Int32.Parse(zbarvalue.Text);
int speedwait = speed.Value;
int position1 =canvas.Width / 2 ;
int position2 = canvas.Height / 2;
for (double i = 0; i <=360; i = i + 0.5)
{
double angle= Math.PI * i / 180.0;
// double angle = i * 0.01745;
float position1x = (float)( position1+Math.Sin(angle)*Theta);
float position1y = (float)( position2+Math.Cos(angle)*Theta2);
float position2x = (float)(position1 + Math.Sin(angle) *radiusy1);
float position2y = (float)(position2 + Math.Cos(angle) * radiusz1);
float position3x = (float)(position1 + Math.Sin(angle) *radiusx1);
float position3y = (float)(position2 + Math.Cos(angle) *radiusz1);
// Graphics g;
// g = canvas.CreateGraphics();
//Pen p;
// Rectangle r;
// p = new Pen(Brushes.Blue);
// r = new Rectangle(position2x,position2y, 1, 1);
// g.DrawRectangle(p, r);
System.Threading.Thread.Sleep(speedwait);
canvas.Refresh();
px.Text = Convert.ToString(position1x);
py.Text = Convert.ToString(position1y);
// pz.Text = Convert.ToString(position1z);
px.Refresh();
py.Refresh();
// pz.Refresh();
System.Drawing.Pen myPen;
System.Drawing.Pen myPen2;
System.Drawing.Pen myPen3;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen2 = new System.Drawing.Pen(System.Drawing.Color.Black);
myPen3 = new System.Drawing.Pen(System.Drawing.Color.Blue);
System.Drawing.Graphics formGraphics = canvas.CreateGraphics();
formGraphics.DrawLine(myPen, position1, position2, position1x, position1y);
formGraphics.DrawLine(myPen2, position1, position2,position2x,position2y);
formGraphics.DrawLine(myPen3, position1, position2,position3x, position3y);
};
}
我的第一种方法是在旋转线上使用椭圆形,以产生深度错觉
有人可以教我如何用c#编写基本的旋转代码,但是数组有问题。
如果您添加对WindowsBase和PresentationCore的引用,则存在可以帮助您进行3D转换的对象。 这些程序集是基本.NET Framework的一部分,不需要像DirectX一样安装任何其他库。 例:
using System.Windows.Media.Media3D;
...
// Define a 90 degree rotation about Y axis
var rotation = new AxisAngleRotation(new Vector(0,1,0), 90);
// Create transformation from our rotation definition
var transform = new RotateTransform3D(rotation);
// Rotate a point using the transformation
var original = new Vector3D(1, 1, 1);
var rotated = transform.Transform(original);
但是,为了在2D曲面上绘制3D对象,您将必须使用投影矩阵。 透视投影使对象看起来更小,而平行投影则可以在所有距离上保持大小。 投影矩阵是将3D向量转换为可在屏幕上使用的2D向量的最后一步。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.