Skip to content

Commit

Permalink
Orient major axis of contour to point in negative direction.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrnhines committed Sep 19, 2023
1 parent ce2c143 commit 8bd8b92
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions share/lib/hoc/import3d/import3d_gui.hoc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,14 +1227,21 @@ proc contour2centroid() {local i, j, imax, imin, ok localobj mean, pts, d, max,
tobj = m.symmeig(m)
// major axis is the one with largest eigenvalue
major = m.getcol(tobj.max_ind)
// For plotting and round-off error consistency
// want major axis to point in negative direction.
// i.e. greatest value is negative.
if (major.x[major.c.abs().max_ind()] > 0) {
printf("reorient major\n")
major.mul(-1)
}
// minor is normal and in xy plane
minor = m.getcol(3-tobj.min_ind-tobj.max_ind)
minor.x[2] = 0
minor.div(minor.mag)
if (g != nil) {
g.beginline(4, 3) g.line(mean.x[0], mean.x[1])
g.line(mean.x[0] + 20*major.x[0], mean.x[1] + 20*major.x[1]) g.flush
}
if (g != nil) {
g.beginline(4, 3) g.line(mean.x[0], mean.x[1])
g.line(mean.x[0] + 20*major.x[0], mean.x[1] + 20*major.x[1]) g.flush
}
d = new Vector(pts.ncol)
rad = new Vector(pts.ncol)
for i=0, pts.ncol-1 {
Expand Down Expand Up @@ -1297,7 +1304,6 @@ if (g != nil) g.line(tobj.x[0], tobj.x[1]) g.flush
for i=1,3 { $oi = pts.getrow(i-1) }
// print d d.printf print rad rad.printf
// print side2 side2.printf print rad2 rad2.printf
orient($o1, $o2, $o3, $o4) // 0 end first
}

proc contourstack2centroid() {local i, j, area, d localobj c
Expand All @@ -1310,29 +1316,6 @@ proc contourstack2centroid() {local i, j, area, d localobj c
c = $o5.contour_list.object(j).approximate_contour_by_circle(&d)
$o4.append(d) for i=1,3 { $oi.append(c.x[i-1]) }
}
orient($o1, $o2, $o3, $o4) // 0 end first
}

proc orient() { local i, n1, r localobj v1
// first point defines the 0 end. If we want that to be the 1 end,
// then reverse.
r = 0 // do not reverse
n1 = $o1.size() - 1
v1 = new Vector(3)
v1.x[0] = $o1.x[n1] - $o1.x[0]
v1.x[1] = $o2.x[n1] - $o2.x[0]
v1.x[2] = $o3.x[n1] - $o3.x[0]
// reverse if largest direction not positive
i = v1.c().abs().max_ind()
if (v1.x[i] < 0) {
r = 1
}
if (r) {
$o1.reverse()
$o2.reverse()
$o3.reverse()
$o4.reverse()
}
}

proc name() {
Expand Down

0 comments on commit 8bd8b92

Please sign in to comment.