我知道有一個二維坐標的類,但是怎么樣也沒辦法做到三維坐標,求大佬解答
uj5u.com熱心網友回復:
public class ThreeDimensional(
public double X{get;set;}
public double Y{get;set;}
public double Z{get;set;}
)
多簡單粗暴
uj5u.com熱心網友回復:
使用C#和微軟的托管D3D開發,資料資源來源于互聯網高程是使用GDAL庫讀取自TIFF檔案
讀取TIFF原始碼下載 https://download.csdn.net/download/mosangbike/6667651
C#圖形影像技術交流群
uj5u.com熱心網友回復:
那豈不是用結構體更好?uj5u.com熱心網友回復:
arr[][] 就成uj5u.com熱心網友回復:
float[][][] axis = new float[][][] {}uj5u.com熱心網友回復:
多維陣列感覺能做這個事uj5u.com熱心網友回復:
舉例立方體操作的定義
using System;
public class Math3D
{
public class Point3D
{
public double X;
public double Y;
public double Z;
public Point3D(int x, int y, int z)
{
X = x;
Y = y;
Z = z; // 例子里設定為1了
}
public Point3D(float x, float y, float z)
{
X = (double)x;
Y = (double)y;
Z = (double)z;
}
public Point3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public Point3D()
{
}
public override string ToString()
{
return "(" + X.ToString() + ", " + Y.ToString() + ", " + Z.ToString() + ")";
}
}
public class Camera
{
public Point3D Position = new Point3D();
}
public static Point3D RotateX(Point3D point3D, double degrees)
{
double cDegrees = (Math.PI * degrees) / 180.0f;
double cosDegrees = Math.Cos(cDegrees);
double sinDegrees = Math.Sin(cDegrees);
double y = (point3D.Y * cosDegrees) + (point3D.Z * sinDegrees);
double z = (point3D.Y * -sinDegrees) + (point3D.Z * cosDegrees);
return new Point3D(point3D.X, y, z);
}
public static Point3D RotateY(Point3D point3D, double degrees)
{
double cDegrees = (Math.PI * degrees) / 180.0;
double cosDegrees = Math.Cos(cDegrees);
double sinDegrees = Math.Sin(cDegrees);
double x = (point3D.X * cosDegrees) + (point3D.Z * sinDegrees);
double z = (point3D.X * -sinDegrees) + (point3D.Z * cosDegrees);
return new Point3D(x, point3D.Y, z);
}
public static Point3D RotateZ(Point3D point3D, double degrees)
{
double cDegrees = (Math.PI * degrees) / 180.0;
double cosDegrees = Math.Cos(cDegrees);
double sinDegrees = Math.Sin(cDegrees);
double x = (point3D.X * cosDegrees) + (point3D.Y * sinDegrees);
double y = (point3D.X * -sinDegrees) + (point3D.Y * cosDegrees);
return new Point3D(x, y, point3D.Z);
}
public static Point3D Translate(Point3D points3D, Point3D oldOrigin, Point3D newOrigin)
{
Point3D difference = new Point3D(newOrigin.X - oldOrigin.X, newOrigin.Y - oldOrigin.Y, newOrigin.Z - oldOrigin.Z);
points3D.X += difference.X;
points3D.Y += difference.Y;
points3D.Z += difference.Z;
return points3D;
}
public static Point3D[] RotateX(Point3D[] points3D, double degrees)
{
for (int i = 0; i < points3D.Length; i++)
{
points3D[i] = RotateX(points3D[i], degrees);
}
return points3D;
}
public static Point3D[] RotateY(Point3D[] points3D, double degrees)
{
for (int i = 0; i < points3D.Length; i++)
{
points3D[i] = RotateY(points3D[i], degrees);
}
return points3D;
}
public static Point3D[] RotateZ(Point3D[] points3D, double degrees)
{
for (int i = 0; i < points3D.Length; i++)
{
points3D[i] = RotateZ(points3D[i], degrees);
}
return points3D;
}
public static Point3D[] Translate(Point3D[] points3D, Point3D oldOrigin, Point3D newOrigin)
{
for (int i = 0; i < points3D.Length; i++)
{
points3D[i] = Translate(points3D[i], oldOrigin, newOrigin);
}
return points3D;
}
}
寬度為1的例子 https://pan.baidu.com/s/1rDjOj-_OC6W0v8iaMl_jNQ
uj5u.com熱心網友回復:
arr[][] 就成double[][] matix=new double[][]{{x1,y1,z1},{x2,y2,z3}}
uj5u.com熱心網友回復:
非常感謝,總體思想就是new一個新的類來存盤xyz三個坐標咯
uj5u.com熱心網友回復:
可以是可以,但是這個點位比較多,我希望把他做到可視化,就好比這個點,是結束點,EndPoint(1,2,3)這種
uj5u.com熱心網友回復:
public struct P3d{ public double x; public double y; public double z;}uj5u.com熱心網友回復:
結束點這個要求是邏輯要求,不是資料結構要求(資料結構上多維陣列。或者一維多向量物件,或者一維元組)。所以這種要求你就得按樓上那些做法,定義物件(無論是結構體,還是class),當然
new EndPoint(1,2,3) 無非是構造。
ps:這種東西在資料結構上怎么選都可以,比如C++,python的最可能的選擇是vector向量,因為這個記憶體是連續的,訪問快
uj5u.com熱心網友回復:
微軟也提供了3d向量物件(vector3d),不過這東西就不在常用命名空間里面了,屬于比較專用的東西https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.media.media3d.vector3d?redirectedfrom=MSDN&view=netframework-4.8
uj5u.com熱心網友回復:
我幫你在 LinqPad 上寫了一個測驗程式,你參考一下吧
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/133027.html
標籤:C#
上一篇:EmguCV做人臉檢測時遇到找不到檔案 :haarcascade_frontalface_default.xml
