英文:
How to rotate a Text In HelixToolkit
问题
I understand your request. Here's the translated code portion:
我正在尝试插入一个带有旋转对齐的TextVisual3D。如果原点是零,没有问题,但当原点位于其他位置时,变换会移动两倍的距离。
我已经尝试了许多方法,但没有成功。
我正在使用"Up"视图,UpDirection使用矢量(0, 1, 0)来放置文本。
var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;
text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();
if (Rotation != 0)
{
var angle = Rotation.Round(0);
if (angle.Abs() != 360)
{
var axis = new Vector3D(0, 0, 1);
var matrix = text.Transform.Value;
matrix.Rotate(new Quaternion(axis, angle));
text.Transform = new MatrixTransform3D(matrix);
}
}
return text;
Please let me know if you need any further assistance.
英文:
I'm trying to insert a TextVisual3D with rotated alignment. If the origin point is zero, no problem, but when the origin is in other location, the transform moves 2 times the distance.
I've tried many ways, with no success.
I'm using the "Up" view, the UpDirection is using the Vector (0, 1, 0), to plain the text.
var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;
text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();
if (Rotation!=0)
{
var angle = Rotation.Round(0);
if(angle.Abs()!=360)
{
var axis = new Vector3D(0,0,1);
var matrix = text.Transform.Value;
matrix.Rotate(new Quaternion(axis, angle));
text.Transform = new MatrixTransform3D(matrix);
}
}
return text;
The Result:
Expected:
答案1
得分: 0
以下是您要翻译的部分:
"After so many attempts, I've discovered the solution.
var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;
text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();
if (Rotation != 0)
{
var angle = Rotation.Round(0);
if (angle.Abs() != 360)
{
var axis = new Vector3D(0, 0, 1);
var matrix = text.Transform.Value;
var rotate = new RotateTransform3D();
var angle_axis = new AxisAngleRotation3D();
angle_axis.Angle = angle;
angle_axis.Axis = axis;
rotate.Rotation = angle_axis;
rotate.CenterX = origin.X;
rotate.CenterY = origin.Y;
text.Transform = rotate;
}
}
return text;"
结果:
英文:
After so many attempts, I've discovered the solution.
var text = new TextVisual3D();
text.Foreground = Brushes.Cyan;
text.FontSize = size / 4;
text.Height = size * 2;
text.Text = value;
text.UpDirection = new Vector3D(0, 1, 0);
text.HorizontalAlignment = horizontal;
text.VerticalAlignment = vertical;
text.Position = origin.GetPoint3D();
if (Rotation != 0)
{
var angle = Rotation.Round(0);
if (angle.Abs() != 360)
{
var axis = new Vector3D(0, 0, 1);
var matrix = text.Transform.Value;
var rotate = new RotateTransform3D();
var angle_axis = new AxisAngleRotation3D();
angle_axis.Angle = angle;
angle_axis.Axis = axis;
rotate.Rotation = angle_axis;
rotate.CenterX = origin.X;
rotate.CenterY = origin.Y;
text.Transform = rotate;
}
}
return text;
Result:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论