Hello everyone,
On c# component, I have in input any 3D points.
I would to calculate the two smallest vectors between my first point ( item 0 ) and the other points. I want draw a 3d face between my first point and the 2 points who are closest.
After, I want to make the same operation with the second point, and so on.
I begin in c# and i don’t know how i can write my code.
Thank you for your help.
Hmm … not exactly the ideal start for walking the walk. I would strongly suggest some easier tasks at present time.
Anyway get it and have (?) some (?) fun (?)
Points_ProxConnectivity_EntryLevel_V1.gh (116.1 KB)
Thank for file. I’m going to see this.
I know that my first program his hard… I already wrote a same code for an other language ( for Autocad ). I wasn’t thinking it was hard…
The general case is a constrainet clsssic K-Means clustering. If you are serious about learning C# … and after some time and if/when your are ready … drop a word for a (public) demo on that particular task of yours (on the image captured criterium is N of clusters, yellows are the cluster centers).
Hello
I have a new problem ( i think it’s easy…). I have convert my Point3d to string, now, i want make string to Point3d.
I don’t know how convert this… Can help me ?
Yes, thank you !
I had tried a similar method.
I didn’t have “double coord= new double[3];” and I couldn’t create a list of points without going through “double”.
as well, I I was looking to convert the text directly, like Convert.To…
I’ve added a new Point3d.TryParse
method for Rhino 6 SR12.
https://mcneel.myjetbrains.com/youtrack/issue/RH-49436
– Dale
Always me …
I think I have a problem with a condition.
I want to have in “item_triangle_conserve” (in the end) all triangle who are not concerned by my condition.
I don’t know i my code is understandable…
List<string> item_triangle_conserve = new List<string>(); //List of triangles that I want to keep ( normally 4 )
for(int i = 0; i < Listetriangle.Count; i++) // listetriangle = 9 triangles, coordinates XYZ are string : 0.000,1.000,2.000
{
string [] point = Listetriangle[i].Split(new Char [] {' '}); // separation of coordinates for 1 line = 1 vertex
for (int j = 0; j < pts.Count; j++) // number of points : 5;
{
string point_texte_comp = pts[j].ToString(); // point comparison
int Bool0 = point_texte_comp.CompareTo(point[0]);
int Bool1 = point_texte_comp.CompareTo(point[1]);
int Bool2 = point_texte_comp.CompareTo(point[2]);
//
if( 0 != (Bool0 | Bool1 | Bool2))
{
double Distance_centre_point = n_pts_cercle[i].DistanceTo(pts[j]); // n_pts_cercle = number of triangle
if (Distance_centre_point <= n_rayon_cercle[i]) // n_rayon_cercle = number of triangle
{
break;;
}
else
{
item_triangle_conserve.Add(Listetriangle[i]);
}
}
}
F = item_triangle_conserve;
}
I have tested :
List<string> item_triangle = new List<string>(); //List of triangles that I want to keep ( normally 4 )
for (int j = 0; j < pts.Count; j++) // number of points : 5;
{
List<string> item_triangle_conserve = new List<string>(); //List of triangles that I want to keep ( normally 4 )
int i = 0;
while ( i < Listetriangle.Count )
{
string [] point = Listetriangle[i].Split(new Char [] {' '}); // separation of coordinates for 1 line = 1 vertex
string point_texte_comp = pts[j].ToString(); // point comparison
int Bool0 = point_texte_comp.CompareTo(point[0]);
int Bool1 = point_texte_comp.CompareTo(point[1]);
int Bool2 = point_texte_comp.CompareTo(point[2]);
if( 0 != (Bool0 | Bool1 | Bool2))
{
double Distance_centre_point = n_pts_cercle[i].DistanceTo(pts[j]);
if (Distance_centre_point <= n_rayon_cercle[i])
{
break;;
}
else
{
item_triangle_conserve.Add(Listetriangle[i]);
}
}
i++;
}
item_triangle.Add(item_triangle_conserve);
}
F = item_triangle;
but i have an error message. ( (…) impossible to convert List to’string’ )…
Er …
- Provide the FULL thingy (ALWAYS do that): the C# , the test data (internalized or not), the cat, the dog and whatever else is required (maybe an alligator?).
- See 1.
- See 2.
…
PS: Why you do business with Points as strings? Are they sourced from some, say, Excel ?
The Add method wants a string but gets a List of strings. If you want to add a collection of items to a list, you have to use AddRange(). That’s also what the error message says. Usually you should be also able to track this straight away by looking at the error code, it usually states the line where the Error occurs, making it easier to debug. If it doesn’t show it, encapsulate the code in a try/catch, you can then trace back to which command line raised the exception and thus created the Error.
the whole code ;
private void RunScript(List pts3d, object y, ref object A, ref object B, ref object C, ref object D, ref object E, ref object F, ref object G, ref object H)
{
List pts = pts3d;
A = pts;//pour lecture des points
// Calcul de tous les triangles possibles
List<string> Listetriangle = new List<string>();
//List<string> Lsommets_rentenu = new List<string>();
for(int indx = 0; indx < pts.Count; indx++ )
{
int indx1 = indx + 1;
while (indx1 < pts.Count)
{
int indx2 = indx1 + 1;
while (indx2 < pts.Count)
{
Listetriangle.Add(pts[indx].ToString() + " " + pts[indx1].ToString() + " " + pts[indx2].ToString());
indx2++;
}
indx1++;
}
B = Listetriangle; // liste des triangles en texte (
}
List<Point3d> n_pts_cercle = new List<Point3d>();
List<double> n_rayon_cercle = new List<double>();
List<double> dst_cercle_point = new List<double>();
DataTree<Surface> surface = new DataTree<Surface>();
List<int> Lsommets_rentenu = new List<int>();
// Transformation des coordonnées texte en point 3d
for (int i = 0; i < Listetriangle.Count; i++)
{
string [] point = Listetriangle[i].Split(new Char [] {' '});
string [] coori = point[0].Split(',');
string [] coorj = point[1].Split(',');
string [] coork = point[2].Split(',');
//transofmation des textes en double
double[] coordi = new double[3];
double[] coordj = new double[3];
double[] coordk = new double[3];
for (int j = 0; j < coori.Length; j++)
{
coordi[j] = Convert.ToDouble(coori[j]);
coordj[j] = Convert.ToDouble(coorj[j]);
coordk[j] = Convert.ToDouble(coork[j]);
}
//calcul des médiatrices
//médiatrice 1
double med_a1 = 2 * (coordj[0] - coordi[0]);
double med_b1 = 2 * (coordj[1] - coordi[1]);
double med_c1 = (coordi[0] * coordi[0]) + (coordi[1] * coordi[1]) - (coordj[0] * coordj[0]) - (coordj[1] * coordj[1]);
//médiatrice 2
double med_a2 = 2 * (coordk[0] - coordi[0]);
double med_b2 = 2 * (coordk[1] - coordi[1]);
double med_c2 = (coordi[0] * coordi[0]) + (coordi[1] * coordi[1]) - (coordk[0] * coordk[0]) - (coordk[1] * coordk[1]);
//intersection des médiatrices
double int_med_x = (med_c1 * med_b2 - (med_c2 * med_b1)) / (med_a2 * med_b1 - (med_a1 * med_b2));
double int_med_y = (med_c1 * med_a2 - (med_a1 * med_c2)) / (med_a1 * med_b2 - (med_b1 * med_a2));
//point centre du cercle
n_pts_cercle.Add(new Point3d (int_med_x, int_med_y, 0));
//calcul du R²
n_rayon_cercle.Add(Math.Sqrt(((coordi[0] - int_med_x) * (coordi[0] - int_med_x)) + ((coordi[1] - int_med_y) * (coordi[1] - int_med_y))));
D = n_pts_cercle;
E = n_rayon_cercle;
}
//List<double> Distance_centre_point = new List<double>();
List<string> item_triangle_conserve = new List<string>(); //List of triangles that I want to keep ( normally 4 )
List<string> item_triangle = new List<string>(); //List of triangles that I want to keep ( normally 4 )
for (int j = 0; j < pts.Count; j++) // number of points : 5;
{
int i = 0;
while ( i < Listetriangle.Count )
{
string [] point = Listetriangle[i].Split(new Char [] {' '}); // separation of coordinates for 1 line = 1 vertex
string point_texte_comp = pts[j].ToString(); // point comparison
int Bool0 = point_texte_comp.CompareTo(point[0]);
int Bool1 = point_texte_comp.CompareTo(point[1]);
int Bool2 = point_texte_comp.CompareTo(point[2]);
if( 0 != (Bool0 | Bool1 | Bool2))
{
double Distance_centre_point = n_pts_cercle[i].DistanceTo(pts[j]);
if (Distance_centre_point <= n_rayon_cercle[i])
{
break;;
}
else
{
item_triangle_conserve.Add(Listetriangle[i]);
F = item_triangle_conserve;
}
}
i++;
}
}
}
I converted Point3d (Rhino point) to a string so that I could have each triangle vertex on one line.
It’s easy to get started on a project like this, but it’s very interesting!
I want answer to the law of Delaunay :
We check if the triplet satisfies Delaunay’s condition.
For each point that is not already in the triplet
we check if its distance squared with respect to
center of the circle is smaller than the radius squared. Yes
this is the case we destroy the triplet and we stop the loop
at once.
If the distance is greater, keep the triangle. Otherwise we ignore Triangle because this
is not the triplet of ideal points that satisfy
the condition of Delaunay. We start again. The loop ends with the last
triplet of three points from this list. We return
the List with the triplets of the three ideal points for
build a Delaunay triangulation in the plane.
Also with the full code availabe, I still think that you are trying to add a collection of items (in this case strings) to another list by using Add(). That won’t work, you need to use AddRange().
If some Delauney (working against “flat” point collections) triangulation (maybe a better than the one available, maybe worst, maybe something in between) is your issue … converting Points to strings is a world’s first. This is NOT the way to cut the mustard on that matter … nor is an entry level task in C# adventures. Plus in most of real-life cases you’ll need to restrict the output into some boundary or to control the output via some other rules/conditions.
If on the other hand you want a C# that does it via GH Methods, notify.