C# .NET - how can i define xyz coordinates in csharp

Asked By ned on 23-May-10 04:11 AM
end of post
Anoop S replied to ned on 23-May-10 05:48 AM
You need to add a Spherical method to the Matrix3 class.This method transforms a point in the spherical coordinate system to a point in the Cartesian coordinate system.
just refer this example

public Point3 Spherical(float r, float theta, float phi)
{
    Point3 pt = new Point3();
    float snt = (float)Math.Sin(theta * Math.PI / 180);
    float cnt = (float)Math.Cos(theta * Math.PI / 180);
    float snp = (float)Math.Sin(phi * Math.PI / 180);
    float cnp = (float)Math.Cos(phi * Math.PI / 180);
    pt.X = r * snt * cnp;
    pt.Y = r * cnt;
    pt.Z = -r * snt * snp;
    pt.W = 1;
    return pt;
}

Goniey N replied to ned on 24-May-10 04:26 AM

calculating the surface and vertex normals & surface is triangulated 3D closed mesh...


void calcNormal(float v[3][3], float out[3])                            // Calculates Normal For A Quad Using 3 Points
{
    float v1[3],v2[3];                                          // Vector 1 (x,y,z) & Vector 2 (x,y,z)
    static const int x = 0;                                             // Define X Coord
    static const int y = 1;                                             // Define Y Coord
    static const int z = 2;                                             // Define Z Coord

    // Finds The Vector Between 2 Points By Subtracting
    // The x,y,z Coordinates From One Point To Another.

    // Calculate The Vector From Point 1 To Point 0
    v1[x] = v[0][x] - v[1][x];                                  // Vector 1.x=Vertex[0].x-Vertex[1].x
    v1[y] = v[0][y] - v[1][y];                                  // Vector 1.y=Vertex[0].y-Vertex[1].y
    v1[z] = v[0][z] - v[1][z];                                  // Vector 1.z=Vertex[0].y-Vertex[1].z
    // Calculate The Vector From Point 2 To Point 1
    v2[x] = v[1][x] - v[2][x];                                  // Vector 2.x=Vertex[0].x-Vertex[1].x
    v2[y] = v[1][y] - v[2][y];                                  // Vector 2.y=Vertex[0].y-Vertex[1].y
    v2[z] = v[1][z] - v[2][z];                                  // Vector 2.z=Vertex[0].z-Vertex[1].z
    // Compute The Cross Product To Give Us A Surface Normal
    out[x] = v1[y]*v2[z] - v1[z]*v2[y];                         // Cross Product For Y - Z
    out[y] = v1[z]*v2[x] - v1[x]*v2[z];                         // Cross Product For X - Z
    out[z] = v1[x]*v2[y] - v1[y]*v2[x];                         // Cross Product For X - Y

    ReduceToUnit(out);                                          // Normalize The Vectors
}
ned replied to Goniey N on 12-Jun-10 09:29 AM
thanx alot for ur reply
i didnt get the idea of defining this type of class ,can u brief me plz,.
actually i want to send x y z coordinates values simultaneously to the robotic arm using lpt(parallel port)in csharp?

plz plz guide me ,thanx again for ur reply