Алгоритм пересчета координат из OCS в WCS
| Правила | Регистрация | Пользователи | Сообщения за день |  Справка по форуму | Файлообменник |

Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > Алгоритм пересчета координат из OCS в WCS

Алгоритм пересчета координат из OCS в WCS

Ответ
Поиск в этой теме
Непрочитано 26.10.2014, 08:55 #1
Алгоритм пересчета координат из OCS в WCS
Infi100%
 
Регистрация: 26.10.2014
Сообщений: 3

Доброго времени суток.

Как пересчитать в глобальную систему координат координаты вершин полилинии, которая сохранена в DXF файле как LWPOLYLINE? Из DXF файла можно прочитать координаты вершин и три числа блоков 210, 220 и 230, по которым и вычисляются глобальные координаты. Нашёл алгоритм расчёта матрицы http://www.autodesk.com/techpubs/aut...thm_dxf_ab.htm, а как дальше рассчитывать не могу найти?

Преобразование будет выполняться во внешнем приложении, а не в плагине AutoCAD.

Спасибо.
Просмотров: 4031
 
Непрочитано 26.10.2014, 12:08
#2
100k

Жалкий инженеришка-проектаст
 
Регистрация: 31.01.2010
Сообщений: 1,986


В любом учебнике по САПР и графике.
Матрица преобразования она же перехода она же поворота.
100k вне форума  
 
Автор темы   Непрочитано 26.10.2014, 12:20
#3
Infi100%


 
Регистрация: 26.10.2014
Сообщений: 3


Не могу найти какие коэффициенты используются для расчёта этих матриц
Infi100% вне форума  
 
Непрочитано 26.10.2014, 12:39
#4
100k

Жалкий инженеришка-проектаст
 
Регистрация: 31.01.2010
Сообщений: 1,986


Там нет к-тов. Есть 2 системы координат описываемые точкой начала, и 2 оси Х У описываемые векторами, ось Z перпендикулярна плоскости Х Y
Перевод координатной системы выглядит примерно так
Код:
[Выделить все]
			public static class MatrixFactory
	{
		public static Matrix Rotate(double Angle, Vector Axis)
		{
			Matrix matrix = new Matrix();
			if (Angle == 0.0)
			{
				return matrix;
			}
			Vector normal = Axis.GetNormal();
			double num = normal.X * normal.Y;
			double num2 = normal.X * normal.Z;
			double num3 = normal.Y * normal.Z;
			double num4 = Math.Cos(Angle);
			double num5 = Math.Sin(Angle);
			matrix[0, 0] = normal.X * normal.X * (1.0 - num4) + num4;
			matrix[1, 0] = num * (1.0 - num4) + normal.Z * num5;
			matrix[2, 0] = num2 * (1.0 - num4) - normal.Y * num5;
			matrix[0, 1] = num * (1.0 - num4) - normal.Z * num5;
			matrix[1, 1] = normal.Y * normal.Y * (1.0 - num4) + num4;
			matrix[2, 1] = num3 * (1.0 - num4) + normal.X * num5;
			matrix[0, 2] = num2 * (1.0 - num4) + normal.Y * num5;
			matrix[1, 2] = num3 * (1.0 - num4) - normal.X * num5;
			matrix[2, 2] = normal.Z * normal.Z * (1.0 - num4) + num4;
			return matrix;
		}
		public static Matrix ToCoordinateSystem(CoordinateSystem CoordSys)
		{
			Matrix matrix = new Matrix();
			Point origin = CoordSys.Origin;
			Vector normal = CoordSys.AxisX.GetNormal();
			Vector normal2 = CoordSys.AxisY.GetNormal();
			Vector normal3 = Vector.Cross(CoordSys.AxisX, CoordSys.AxisY).GetNormal();
			matrix[0, 0] = normal.X;
			matrix[1, 0] = normal.Y;
			matrix[2, 0] = normal.Z;
			matrix[0, 1] = normal2.X;
			matrix[1, 1] = normal2.Y;
			matrix[2, 1] = normal2.Z;
			matrix[0, 2] = normal3.X;
			matrix[1, 2] = normal3.Y;
			matrix[2, 2] = normal3.Z;
			matrix[3, 0] = -(origin.X * normal.X + origin.Y * normal.Y + origin.Z * normal.Z);
			matrix[3, 1] = -(origin.X * normal2.X + origin.Y * normal2.Y + origin.Z * normal2.Z);
			matrix[3, 2] = -(origin.X * normal3.X + origin.Y * normal3.Y + origin.Z * normal3.Z);
			return matrix;
		}
		public static Matrix FromCoordinateSystem(CoordinateSystem CoordSys)
		{
			Matrix matrix = new Matrix();
			Point origin = CoordSys.Origin;
			Vector normal = CoordSys.AxisX.GetNormal();
			Vector normal2 = CoordSys.AxisY.GetNormal();
			Vector normal3 = Vector.Cross(CoordSys.AxisX, CoordSys.AxisY).GetNormal();
			matrix[0, 0] = normal.X;
			matrix[1, 0] = normal2.X;
			matrix[2, 0] = normal3.X;
			matrix[0, 1] = normal.Y;
			matrix[1, 1] = normal2.Y;
			matrix[2, 1] = normal3.Y;
			matrix[0, 2] = normal.Z;
			matrix[1, 2] = normal2.Z;
			matrix[2, 2] = normal3.Z;
			matrix[3, 0] = origin.X;
			matrix[3, 1] = origin.Y;
			matrix[3, 2] = origin.Z;
			return matrix;
		}
		public static Matrix ByCoordinateSystems(CoordinateSystem CoordSys1, CoordinateSystem CoordSys2)
		{
			Matrix a = MatrixFactory.FromCoordinateSystem(CoordSys1);
			Matrix b = MatrixFactory.ToCoordinateSystem(CoordSys2);
			return b * a;
		}
	}
	public class Matrix
	{
		private double[,] Transformation;
		public double this[int row, int column]
		{
			get
			{
				return this.Transformation[row, column];
			}
			set
			{
				this.Transformation[row, column] = value;
			}
		}
		public Matrix()
		{
			this.Transformation = new double[,]
			{
				
				{
					1.0,
					0.0,
					0.0
				},
				
				{
					0.0,
					1.0,
					0.0
				},
				
				{
					0.0,
					0.0,
					1.0
				},
				
				{
					0.0,
					0.0,
					0.0
				}
			};
		}
		public Matrix(Matrix m)
		{
			this.Transformation = (double[,])m.Transformation.Clone();
		}
		public void Transpose()
		{
			double num = this.Transformation[0, 1];
			this.Transformation[0, 1] = this.Transformation[1, 0];
			this.Transformation[1, 0] = num;
			num = this.Transformation[0, 2];
			this.Transformation[0, 2] = this.Transformation[2, 0];
			this.Transformation[2, 0] = num;
			num = this.Transformation[1, 2];
			this.Transformation[1, 2] = this.Transformation[2, 1];
			this.Transformation[2, 1] = num;
			double num2 = this.Transformation[3, 0];
			double num3 = this.Transformation[3, 1];
			double num4 = this.Transformation[3, 2];
			this.Transformation[3, 0] = -(num2 * this.Transformation[0, 0] + num3 * this.Transformation[1, 0] + num4 * this.Transformation[2, 0]);
			this.Transformation[3, 1] = -(num2 * this.Transformation[0, 1] + num3 * this.Transformation[1, 1] + num4 * this.Transformation[2, 1]);
			this.Transformation[3, 2] = -(num2 * this.Transformation[0, 2] + num3 * this.Transformation[1, 2] + num4 * this.Transformation[2, 2]);
		}
		public Matrix GetTranspose()
		{
			Matrix matrix = new Matrix(this);
			matrix.Transpose();
			return matrix;
		}
		public static Matrix operator *(Matrix B, Matrix A)
		{
			Matrix matrix = new Matrix();
			double num = A.Transformation[3, 0];
			double num2 = A.Transformation[3, 1];
			double num3 = A.Transformation[3, 2];
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					matrix.Transformation[j, i] = A.Transformation[0, i] * B.Transformation[j, 0] + A.Transformation[1, i] * B.Transformation[j, 1] + A.Transformation[2, i] * B.Transformation[j, 2];
				}
				matrix.Transformation[3, i] = B.Transformation[0, i] * num + B.Transformation[1, i] * num2 + B.Transformation[2, i] * num3 + B.Transformation[3, i];
			}
			return matrix;
		}
		public Point Transform(Point p)
		{
			return new Point
			{
				X = p.X * this.Transformation[0, 0] + p.Y * this.Transformation[1, 0] + p.Z * this.Transformation[2, 0] + this.Transformation[3, 0],
				Y = p.X * this.Transformation[0, 1] + p.Y * this.Transformation[1, 1] + p.Z * this.Transformation[2, 1] + this.Transformation[3, 1],
				Z = p.X * this.Transformation[0, 2] + p.Y * this.Transformation[1, 2] + p.Z * this.Transformation[2, 2] + this.Transformation[3, 2]
			};
		}
		public static Point operator *(Matrix A, Point p)
		{
			return A.Transform(p);
		}
		public override string ToString()
		{
			return string.Concat(new string[]
			{
				"[",
				this.Transformation[0, 0].ToString("f4"),
				" ",
				this.Transformation[0, 1].ToString("f4"),
				" ",
				this.Transformation[0, 2].ToString("f4"),
				"]\n[",
				this.Transformation[1, 0].ToString("f4"),
				" ",
				this.Transformation[1, 1].ToString("f4"),
				" ",
				this.Transformation[1, 2].ToString("f4"),
				"]\n[",
				this.Transformation[2, 0].ToString("f4"),
				" ",
				this.Transformation[2, 1].ToString("f4"),
				" ",
				this.Transformation[2, 2].ToString("f4"),
				"]\n[",
				this.Transformation[3, 0].ToString("f4"),
				" ",
				this.Transformation[3, 1].ToString("f4"),
				" ",
				this.Transformation[3, 2].ToString("f4"),
				"]\n"
			});
		}
	}
100k вне форума  
 
Автор темы   Непрочитано 26.10.2014, 12:50
#5
Infi100%


 
Регистрация: 26.10.2014
Сообщений: 3


Вот пример но что то не сходиться по вашим формула

POLYLINE
5
19FB5
8
21
6
CONTINUOUS
62
7
66
1
10
0.0
20
0.0
30
291.41995833766282
70
1
210
0.22719739721202
220
-0.002136602687578
230
0.9738463829727146
0
VERTEX
5
1A6AB
8
21
6
CONTINUOUS
62
7
10
1068.975922707793
20
-601.60257833956075
30
291.41995833766282
0
Infi100% вне форума  
 
Непрочитано 26.10.2014, 12:55
#6
100k

Жалкий инженеришка-проектаст
 
Регистрация: 31.01.2010
Сообщений: 1,986


Формулы не мои, код тоже не мой. Код C# рабочий, пользую его для преобразований в 3D, "выдернул" из Tekla Structures API. Разбираетесь если есть желание.
100k вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > Алгоритм пересчета координат из OCS в WCS



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Какой язык перспективен для инженера-конструктора с условием The_Mercy_Seat Программирование 705 17.03.2021 14:19
Какая система координат предпочтительна для генплана? randum Прочее. Архитектура и строительство 12 31.10.2013 17:11
Помощь по Лире Серега М Лира / Лира-САПР 52 28.05.2007 02:47
управление системой координат Автокад из Делфей Владимир В Программирование 12 27.04.2005 09:54