Skip to content

Commit 5efc765

Browse files
committed
Fix offset calculation
1 parent fe0d65f commit 5efc765

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

system/lane_detector.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,25 +860,30 @@ bool LaneDetector::generate_vote(segment_t& lane_segment, float& d,
860860

861861
Point2f n_hat(-t_hat.y, t_hat.x); //normal vector
862862

863-
float d1 = inner_product(n_hat, p1);
864-
float d2 = inner_product(n_hat, p2);
865-
866-
d = (d1 + d2) / 2; //lateral displacement
863+
Point2f offset_vector = n_hat;
867864

868865
if(color == WHITE) {
869-
d -= W / 2;
870-
871866
if(lane_segment.side == RIGHT_EDGE) {
872-
d -= L_W;
867+
offset_vector *= -(W / 2) - L_W;
868+
} else {
869+
offset_vector *= -(W / 2);
873870
}
874871
} else if(color == YELLOW) {
875-
d += W / 2;
876-
877872
if(lane_segment.side == LEFT_EDGE) {
878-
d += L_Y;
873+
offset_vector *= +(W / 2) + L_Y;
874+
} else {
875+
offset_vector *= +(W / 2);
879876
}
880877
}
881878

879+
p1 += offset_vector;
880+
p2 += offset_vector;
881+
882+
float d1 = inner_product(n_hat, p1);
883+
float d2 = inner_product(n_hat, p2);
884+
885+
d = (d1 + d2) / 2; //lateral displacement
886+
882887
//TODO:referive the geometry formulas!
883888
d *= -1;
884889

0 commit comments

Comments
 (0)