How to combine selected points to their average point?
Removing all the selected points and replace them with their average point (in xy QCAD or in xyz QCAM)
.
How to combine selected points to one averaged point?
Moderator: andrew
Re: How to combine selected points to one averaged point?
Hi,
remark here that QCAD/CAM is 2D native and only handles z components up to a point.
There a many strategies for that.
In 2D simply the center of the best fitted circle ...
One could take the mean of the first coordinates and the mean of the second coordinates.
or one could take the mean of the magnitudes and the mean of directions of the vectors.
Other strategies may exclude inner points ... exorbitant positions ...
... or the centroid of the hull shape/body ...
All depends.
Collecting data would be done by a script that applies the required calculations.
In your example the selected dots would represent a lot of noise in that area.
I see a mean pathway from left to right using 3 or 4 positions instead of 1 single mean value ...
Regards,
CVH
remark here that QCAD/CAM is 2D native and only handles z components up to a point.
There a many strategies for that.
In 2D simply the center of the best fitted circle ...
One could take the mean of the first coordinates and the mean of the second coordinates.
or one could take the mean of the magnitudes and the mean of directions of the vectors.
Other strategies may exclude inner points ... exorbitant positions ...
... or the centroid of the hull shape/body ...
All depends.
Collecting data would be done by a script that applies the required calculations.
In your example the selected dots would represent a lot of noise in that area.
I see a mean pathway from left to right using 3 or 4 positions instead of 1 single mean value ...
Regards,
CVH
Re: How to combine selected points to one averaged point?
A rather simplistic script for average and mean position ...
It displays the results textual in the Command History and adds both points to the document.
Please:
Regards,
CVH
It displays the results textual in the Command History and adds both points to the document.
Please:
Code: Select all
include("scripts/simple.js");
var doc = this.getDocument();
var xValues = [];
var yValues = [];
var zValues = [];
var ids = doc.querySelectedEntities();
for (var i=0;i<ids.length;i++){
var entity = doc.queryEntityDirect(ids[i]);
if (isPointEntity(entity)){
xValues.push(entity.getPosition().x);
yValues.push(entity.getPosition().y);
zValues.push(entity.getPosition().z);
}
}
var xAve, yAve, zAve;
var xMean, yMean, zMean;
xAve = yAve = zAve = xMean = yMean = zMean = 0.0;
if (xValues.length > 1) {
for (var i=0;i<xValues.length;i++){
xAve += xValues[i]/xValues.length;
yAve += yValues[i]/xValues.length;
zAve += zValues[i]/xValues.length;
xMean += Math.sign(xValues[i])*xValues[i]*xValues[i]/xValues.length;
yMean += Math.sign(yValues[i])*yValues[i]*yValues[i]/xValues.length;
zMean += Math.sign(zValues[i])*zValues[i]*zValues[i]/xValues.length;
}
var avePos = new RVector(xAve, yAve, zAve);
xMean = Math.sign(xMean)*sqrt(Math.abs(xMean));
yMean = Math.sign(yMean)*sqrt(Math.abs(yMean));
zMean = Math.sign(zMean)*sqrt(Math.abs(zMean));
var meanPos = new RVector(xMean, yMean, zMean);
addPoint(avePos);
EAction.handleUserMessage("Average position: " + avePos);
addPoint(meanPos);
EAction.handleUserMessage("Mean position: " + meanPos);
}
else {
EAction.handleUserWarning("No multiple points selected.");
}
CVH