C# 无法创建具有负坐标的平面矩形曲面
我正在尝试从文本文件中的坐标绘制平面。我正在创建一个矩形网格。我面临的问题是,如果我提供所有的正x,y坐标,那么我得到的是矩形曲面。但是,如果我提供负y坐标和正y坐标的组合,曲面就会消失。我无法理解为什么会发生这种情况。 这是我的密码:C# 无法创建具有负坐标的平面矩形曲面,c#,wpf,graphics,3d,C#,Wpf,Graphics,3d,我正在尝试从文本文件中的坐标绘制平面。我正在创建一个矩形网格。我面临的问题是,如果我提供所有的正x,y坐标,那么我得到的是矩形曲面。但是,如果我提供负y坐标和正y坐标的组合,曲面就会消失。我无法理解为什么会发生这种情况。 这是我的密码: <Window x:Class="SurfaceCreation.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="
<Window x:Class="SurfaceCreation.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="SurfaceCreation" Height="500" Width="800" WindowState="Maximized">
<Grid>
<Viewport3D Grid.Row="0" Grid.Column="0"
Name="MainViewport" >
<Viewport3D.Camera>
<PerspectiveCamera Position="200,2,244" LookDirection="0,0,-2" UpDirection="0,1,0"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="White"/>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
</Grid>
</Window>
我的代码隐藏文件:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Controls;
using System.Linq;
using System.Collections;
namespace SurfaceCreation
{
class Surface
{
public string[] rectangles;
private Color lineColor = Colors.Black;
private Color surfaceColor = Colors.Green;
private Point3D center = new Point3D();
private bool isHiddenLine = false;
private bool isWireframe = true;
private Viewport3D viewport3d = new Viewport3D();
public bool IsWireframe
{
get { return isWireframe; }
set { isWireframe = value; }
}
public bool IsHiddenLine
{
get { return isHiddenLine; }
set { isHiddenLine = value; }
}
public Color LineColor
{
get { return lineColor; }
set { lineColor = value; }
}
public Color SurfaceColor
{
get { return surfaceColor; }
set { surfaceColor = value; }
}
public Point3D Center
{
get { return center; }
set { center = value; }
}
public Viewport3D Viewport3d
{
get { return viewport3d; }
set { viewport3d = value; }
}
public void CreateSurface()
{
string[] lines = System.IO.File.ReadAllLines(@"C:\iitm\sem4\project\C#\CreatePath\Path3D.txt").Skip(4).ToArray();
int noOfLines = lines.Length;
ArrayList cLines = new ArrayList();
for (int m = 0; m < lines.Length; m++)
{
if (lines[m].Length != 0)
{
cLines.Add(lines[m]);
}
}
string[] fLines = (String[])cLines.ToArray(typeof(string));
int rowLength = 162;
int columnLength = 101;
rectangles = new string[(rowLength - 1) * (columnLength - 1)];
Point3D[,] pts = new Point3D[rowLength, columnLength];
for (int i = 0; i < rowLength; i++)
{
for (int j = 0; j < columnLength; j++)
{
string[] separators = { ",", "!", "?", ";", ":", " ","\t" };
string point = fLines[i * (columnLength) + j];
string[] x = point.Split(separators, StringSplitOptions.RemoveEmptyEntries);
pts[i, j] = new Point3D(Convert.ToDouble(x[0]), Math.Abs(Convert.ToDouble(x[1])), Convert.ToDouble(x[2]));
}
}
Point3D[] p = new Point3D[4];
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
p[0] = pts[i, j];
p[1] =pts[i + 1, j];
p[2] = pts[i + 1, j + 1];
p[3] = pts[i , j+1];
//Create rectangular face:
if (p[2].Z == 0)
{
SurfaceColor = Colors.Gray;
}
else
{
SurfaceColor = Colors.Black;
}
if (IsHiddenLine == false)
Utility.CreateRectangleFace(
p[0], p[1], p[2], p[3],
SurfaceColor, Viewport3d);
rectangles[i * (columnLength - 1) + j] = (i * (columnLength - 1) + j).ToString() + "," + p[0].ToString() + "," + p[1].ToString() + "," + p[2].ToString() + "," + p[3].ToString();
}
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Windows;
使用System.Windows.Media;
使用System.Windows.Media.Media3D;
使用System.Windows.Controls;
使用System.Linq;
使用系统集合;
命名空间表面复制
{
类表面
{
公共字符串[]矩形;
私有颜色lineColor=颜色。黑色;
私有颜色surfaceColor=颜色。绿色;
私有点3D中心=新点3D();
private bool isHiddenLine=false;
private bool isWireframe=true;
私有视口3D视口3D=新视口3D();
公共线框
{
获取{return isWireframe;}
设置{isWireframe=value;}
}
公共边界线
{
获取{return ishidenline;}
设置{isHiddenLine=value;}
}
公共颜色线条颜色
{
获取{return lineColor;}
设置{lineColor=value;}
}
公共颜色表面颜色
{
获取{return surfaceColor;}
设置{surfaceColor=value;}
}
公共点3D中心
{
获取{返回中心;}
设置{center=value;}
}
公共视口3D视口3D
{
获取{return viewport3d;}
设置{viewport3d=value;}
}
公共void CreateSurface()
{
string[]lines=System.IO.File.ReadAllLines(@“C:\iitm\sem4\project\C#\CreatePath\Path3D.txt”)。跳过(4).ToArray();
int noOfLines=线。长度;
ArrayList cLines=新的ArrayList();
对于(int m=0;m
您确认了没有在相机后面创建它吗?没有。我不这么认为。我正在XY平面上创建曲面,并从Z平面进行查看。如果我去掉负坐标,同样的坐标集,曲面就被创建了。所以你有一组可以看到的坐标,还有一组你看不到的坐标。你的问题中的坐标在哪里?我正在从文本文件中读取坐标。我不知道如何在这里共享文本文件。听起来你好像在告诉我你不知道如何将文本粘贴到堆栈溢出问题中。对吗?